Pomoc - Szukaj - Użytkownicy - Kalendarz
Pełna wersja: [PHP]Błąd uploadu
Forum PHP.pl > Forum > Przedszkole
Johnas
Witam ponownie wszystkich! Mam taki kod uploadu:
  1. <?php
  2. session_start(); // rozpoczęcie sesji
  3. ?>
  4.  
  5.  
  6. <?php include('header.php'); ?>
  7.  
  8. <h2>? Dodaj zdjęcie</h2>
  9. <div class="content">
  10. <?php
  11. include('class.upload.php'); // podłączamy klasę
  12. // BARDZO PROSTY FORMULARZ
  13. echo '<form enctype="multipart/form-data" method="post" action="upload.php">
  14. <input type="file" size="32" name="mojplik" value="">
  15. <input type="submit" name="Submit" value="upload">
  16. </form>';
  17. //Odbieramy dane na temat pliku i tworzymy klasę
  18. //
  19. $mplik = new Upload($_FILES['mojplik']);
  20. if ($mplik->uploaded) {
  21.  
  22. //na jakie pliki pozwalamy. Ja ustawiłem tylko pliki graficzne
  23. $mplik->allowed = array('image/*');
  24. // rozmiar wysyłanych plików
  25. $mplik->file_max_size = '5120'; // max plik 5MB
  26. // nazwa pliku po wgraniu na serwer
  27. $mplik->file_new_name_body = moje_pliki_www;
  28. // jeśli w poleceniu wyżej nie mamy żadnych zmiennych które odróżniały by pliki od siebie trzeba uzyć opcji, auto Renami. Klasa sama zmieni nazwę pliku na inny.
  29. //Najczęściej objawia się to przez dopisanie cyfry na końcu nazwy pliku
  30.  
  31. $mplik->file_auto_rename = true;
  32. // zmieniamy rozmiar zdjęcia na 800x600 symetrycznie do tego potrzebne nam będą te opcje.
  33. // chodzi o to, że zmienimy rozmiar każdego zdjęcia na mniejszy, bo nie potrzebne są nam zdjęcia o rozmiarach 2134x2480 prawda. Dzięki wartością image_ratio_y=true klasa zachowa proporcje.
  34. $mfile->image_resize = true;
  35. $mfile->image_x = 800;
  36. $mfile->image_ratio_y = true;
  37. // folder gdzie ma być zapisany oryginalny plik po drobnym liftingu, czyli zmianie rozmiaru
  38. $mfile->process('img');
  39. // i puszczamy maszynę w ruch
  40. $mfile->processed;
  41.  
  42. //kod OPCJONALNY NIE STOSUJE JEDNOCZEŚCIE z $mfile->processed;
  43.  
  44. if ($mfile->processed) {
  45. echo '<p class="info">Orginalne zdjęcie zostało przeniesione ... OK ...</p>';
  46. } else {
  47. echo 'Problem : ' . $mfile->error;
  48. }
  49. $mfile->image_resize = true;
  50. // rozmiar miniaturki
  51. $mfile->image_x = 100;
  52. // ma być symetryczna, opcja ta pozwala na zachowanie symetrycznego zdjęcia
  53. $mfile->image_ratio_y = true;
  54. // folder gdzie mają być zapisane miniaturki
  55. $mfile->Process('fotografie/miniaturki');
  56. //Oczywiście pyszczamy maszynę w ruch
  57. $mfile->processed;
  58. //kod OPCJONALNY NIE STOSUJE JEDNOCZEŚCIE z $mfile->processed;
  59. if ($mfile->processed) {
  60. echo '<p class="info">Miniaturka została wygenerowana pomyślnie ... OK ...</p>';
  61. // Czyścimy wszystko, co zostało wykonane chodzi tu o zmienne klasy i tmp
  62. $mfile->Clean();
  63. } else {
  64. echo 'Problem : ' . $mfile->error;
  65. }
  66. // napis, jaki ma być na zdjęciu
  67. $mfile->image_text = "NAPIS TESTOWY";
  68. // kolor tekstu
  69. $mfile->image_text_color = '#4169e1';
  70. // rozmiar tekstu
  71. $mfile->image_text_font = 30;
  72. // położenie tekstu B- bottom, L-left inne obcje to
  73. // 'TBLR': top, bottom, left, right
  74. $mfile->image_text_position = 'BL';
  75. // odstęp od ściany w osi X
  76. $mfile->image_text_padding_x = 10;
  77. // odstęp od ściany w osi Y
  78. $mfile->image_text_padding_y = 10;
  79. }


I pokazuje mi taki bład:
Kod
Fatal error: Call to undefined method stdClass::process() in /home/sites/y/yo/you/youphoto.za.pl/upload.php on line 39


Gdzie linia 39 jest odpowiedzialna za wgranie zdjęcia do folderu. Folder jest zrobiony i chmody ustawione na 777. Gdzie jest błąd i jak go mam naprawić? Proszę o pomoc
Fifi209
Cytat(Jonek_1993 @ 1.08.2010, 11:39:52 ) *
I pokazuje mi taki bład:
Kod
Fatal error: Call to undefined method stdClass::process() in /home/sites/y/yo/you/youphoto.za.pl/upload.php on line 39


Gdzie linia 39 jest odpowiedzialna za wgranie zdjęcia do folderu. Gdzie jest błąd i jak go mam naprawić? Proszę o pomoc

W linii 39. ;d A tak serio to nie masz takiej metody w klasie - o czym mówi komunikat.
Johnas
Nie mam i nie wiem o czym on mówi. Pomóżcie. Wiem tylko że ten błąd wywala jak ma dodać pomniejszone zdjęcie do folderu ;(
Znalazłem coś takiego
  1. * if ($handle->uploaded) {
  2. * $handle->file_new_name_body = 'image_resized';
  3. * $handle->image_resize = true;
  4. * $handle->image_x = 100;
  5. * $handle->image_ratio_y = true;
  6. * $handle->process('/home/user/files/');
Fifi209
Cytat(Jonek_1993 @ 1.08.2010, 11:47:48 ) *
Nie mam i nie wiem o czym on mówi. Pomóżcie. Wiem tylko że ten błąd wywala jak ma dodać pomniejszone zdjęcie do folderu ;(
Znalazłem coś takiego
  1. * if ($handle->uploaded) {
  2. * $handle->file_new_name_body = 'image_resized';
  3. * $handle->image_resize = true;
  4. * $handle->image_x = 100;
  5. * $handle->image_ratio_y = true;
  6. * $handle->process('/home/user/files/');

W klasie, którą includujesz do pliku nie ma tej metody.

Poza tym, raz masz $mkfile raz $mkplik
Johnas
Chwila bo nie wgrałem Lang folderu. a to nie jest wina że tego pliku nie edytowałem
Kod
$handle->process('/home/user/files/');

bo w błędzie są inne współrzędne pliku
hondek
$mfile nie jest obiektem klasy Upload, ani żadnym obiektem, więc ciężko żeby mia łmetodę process...
Johnas
to $mfile i $mplik na co zamienić?
hondek
no zobacz, skoro tworzysz obiekt klasy Upload tak:

  1. $mplik = new Upload($_FILES['mojplik']);


a potem chcesz sie odwołać do metody tej klasy przez nieistniejącą zmienna:

  1. $mfile->process('img');


To jedyne co pozostaje to powiedzieć:
Fatal error: Call to undefined method stdClass::process() in /home/sites/y/yo/you/youphoto.za.pl/upload.php on line 39
XP'ek
a co masz dokładnie w pliku class.upload.php ?
Johnas
Tylko teraz pojawia mi się błąd że Problem : Plik za duży. Chociaż wgrałem mały plik 400 x 575

XP'ek
plik class.upload.php jest za duży aby go tu wstawiać bo ma ponad 4000 linijek kodu
Fifi209
Nie widziałem klasy, ale rozmiar pliku podawany jest w bajtach a nie kb

  1. file_max_size = '5120'; // max plik 5MB


jak tutaj. Spróbuj sobie 5mb na bajty zamienić.
Johnas
5 kb i dodało mi miniaturkę blink.gif
Fifi209
Zamiast 5120 wpisz tam 5242880 - to liczba bajtów.
Johnas
to jest liczba kb. Zobacz na ten fragment kodu:
  1. function init() {
  2.  
  3. // overiddable variables
  4. $this->file_new_name_body = ''; // replace the name body
  5. $this->file_name_body_add = ''; // append to the name body
  6. $this->file_name_body_pre = ''; // prepend to the name body
  7. $this->file_new_name_ext = ''; // replace the file extension
  8. $this->file_safe_name = true; // format safely the filename
  9. $this->file_overwrite = false; // allows overwritting if the file already exists
  10. $this->file_auto_rename = true; // auto-rename if the file already exists
  11. $this->dir_auto_create = true; // auto-creates directory if missing
  12. $this->dir_auto_chmod = true; // auto-chmod directory if not writeable
  13. $this->dir_chmod = 0777; // default chmod to use
  14.  
  15. $this->mime_check = true; // checks the mime type against the allowed list
  16. $this->mime_fileinfo = true; // MIME detection with Fileinfo PECL extension
  17. $this->mime_file = true; // MIME detection with UNIX file() command
  18. $this->mime_magic = true; // MIME detection with mime_magic (mime_content_type())
  19. $this->mime_getimagesize = true; // MIME detection with getimagesize()
  20. $this->no_script = true; // turns scripts into test files
  21.  
  22. $val = trim(ini_get('upload_max_filesize'));
  23. $last = strtolower($val{strlen($val)-1});
  24. switch($last) {
  25. case 'g':
  26. $val *= 1024;
  27. case 'm':
  28. $val *= 1024;
  29. case 'k':
  30. $val *= 1024;
  31. }
  32. $this->file_max_size = $val;
  33.  
  34. $this->image_resize = false; // resize the image
  35. $this->image_convert = ''; // convert. values :''; 'png'; 'jpeg'; 'gif'; 'bmp'
  36.  
  37. $this->image_x = 150;
  38. $this->image_y = 150;
  39. $this->image_ratio = false; // keeps aspect ratio with x and y dimensions
  40. $this->image_ratio_crop = false; // keeps aspect ratio with x and y dimensions, filling the space
  41. $this->image_ratio_fill = false; // keeps aspect ratio with x and y dimensions, fitting the image in the space, and coloring the rest
  42. $this->image_ratio_pixels = false; // keeps aspect ratio, calculating x and y so that the image is approx the set number of pixels
  43. $this->image_ratio_no_zoom_in = false;
  44. $this->image_ratio_no_zoom_out = false;
  45. $this->image_ratio_x = false; // calculate the $image_x if true
  46. $this->image_ratio_y = false; // calculate the $image_y if true
  47. $this->jpeg_quality = 85;
  48. $this->jpeg_size = null;
  49. $this->preserve_transparency = false;
  50. $this->image_is_transparent = false;
  51. $this->image_transparent_color = null;
  52. $this->image_background_color = null;
  53. $this->image_default_color = '#ffffff';
  54. $this->image_is_palette = false;
  55.  
  56. $this->image_max_width = null;
  57. $this->image_max_height = null;
  58. $this->image_max_pixels = null;
  59. $this->image_max_ratio = null;
  60. $this->image_min_width = null;
  61. $this->image_min_height = null;
  62. $this->image_min_pixels = null;
  63. $this->image_min_ratio = null;
  64.  
  65. $this->image_brightness = null;
  66. $this->image_contrast = null;
  67. $this->image_threshold = null;
  68. $this->image_tint_color = null;
  69. $this->image_overlay_color = null;
  70. $this->image_overlay_percent = null;
  71. $this->image_negative = false;
  72. $this->image_greyscale = false;
  73.  
  74. $this->image_text = null;
  75. $this->image_text_direction = null;
  76. $this->image_text_color = '#FFFFFF';
  77. $this->image_text_percent = 100;
  78. $this->image_text_background = null;
  79. $this->image_text_background_percent = 100;
  80. $this->image_text_font = 5;
  81. $this->image_text_x = null;
  82. $this->image_text_y = null;
  83. $this->image_text_position = null;
  84. $this->image_text_padding = 0;
  85. $this->image_text_padding_x = null;
  86. $this->image_text_padding_y = null;
  87. $this->image_text_alignment = 'C';
  88. $this->image_text_line_spacing = 0;
  89.  
  90. $this->image_reflection_height = null;
  91. $this->image_reflection_space = 2;
  92. $this->image_reflection_color = '#ffffff';
  93. $this->image_reflection_opacity = 60;
  94.  
  95. $this->image_watermark = null;
  96. $this->image_watermark_x = null;
  97. $this->image_watermark_y = null;
  98. $this->image_watermark_position = null;
  99.  
  100. $this->image_flip = null;
  101. $this->image_rotate = null;
  102. $this->image_crop = null;
  103. $this->image_precrop = null;
  104.  
  105. $this->image_bevel = null;
  106. $this->image_bevel_color1 = '#FFFFFF';
  107. $this->image_bevel_color2 = '#000000';
  108. $this->image_border = null;
  109. $this->image_border_color = '#FFFFFF';
  110. $this->image_frame = null;
  111. $this->image_frame_colors = '#FFFFFF #999999 #666666 #000000';


A czy to by była maksymalna wielkość?
  1. $this->image_x = 150;
  2. $this->image_y = 150;

Jak tak to czemu miniaturke dodało?
Fifi209
Jeżeli nadpisujesz to będzie to liczba bajtów...
Johnas
Miałeś racje była to liczba bajtów ale teraz mam inny problem ponieważ funkcja nie dodaje napisu na zdjęcie sad.gif

Funkca odpowiedzialna za tekst

  1. * <ul>
  2. * <li><b>image_text</b> creates a text label on the image, value is a string, with eventual replacement tokens (default: null)<br>
  3. * <pre>$handle->image_text = 'test';</pre></li>
  4. * <li><b>image_text_direction</b> text label direction, either 'h' horizontal or 'v' vertical (default: 'h')<br>
  5. * <pre>$handle->image_text_direction = 'v';</pre></li>
  6. * <li><b>image_text_color</b> text color for the text label, in hexadecimal (default: #FFFFFF)<br>
  7. * <pre>$handle->image_text_color = '#FF0000';</pre></li>
  8. * <li><b>image_text_percent</b> text opacity on the text label, integer between 0 and 100 (default: 100)<br>
  9. * <pre>$handle->image_text_percent = 50;</pre></li>
  10. * <li><b>image_text_background</b> text label background color, in hexadecimal (default: null)<br>
  11. * <pre>$handle->image_text_background = '#FFFFFF';</pre></li>
  12. * <li><b>image_text_background_percent</b> text label background opacity, integer between 0 and 100 (default: 100)<br>
  13. * <pre>$handle->image_text_background_percent = 50;</pre></li>
  14. * <li><b>image_text_font</b> built-in font for the text label, from 1 to 5. 1 is the smallest (default: 5)<br>
  15. * <pre>$handle->image_text_font = 4;</pre></li>
  16. * <li><b>image_text_x</b> absolute text label position, in pixels from the left border. can be negative (default: null)<br>
  17. * <pre>$handle->image_text_x = 5;</pre></li>
  18. * <li><b>image_text_y</b> absolute text label position, in pixels from the top border. can be negative (default: null)<br>
  19. * <pre>$handle->image_text_y = 5;</pre></li>
  20. * <li><b>image_text_position</b> text label position withing the image, a combination of one or two from 'TBLR': top, bottom, left, right (default: null)<br>
  21. * <pre>$handle->image_text_position = 'LR';</pre></li>
  22. * <li><b>image_text_padding</b> text label padding, in pixels. can be overridden by {@link image_text_padding_x} and {@link image_text_padding_y} (default: 0)<br>
  23. * <pre>$handle->image_text_padding = 5;</pre></li>
  24. * <li><b>image_text_padding_x</b> text label horizontal padding (default: null)<br>
  25. * <pre>$handle->image_text_padding_x = 2;</pre></li>
  26. * <li><b>image_text_padding_y</b> text label vertical padding (default: null)<br>
  27. * <pre>$handle->image_text_padding_y = 10;</pre></li>
  28. * <li><b>image_text_alignment</b> text alignment when text has multiple lines, either 'L', 'C' or 'R' (default: 'C')<br>
  29. * <pre>$handle->image_text_alignment = 'R';</pre></li>
  30. * <li><b>image_text_line_spacing</b> space between lines in pixels, when text has multiple lines (default: 0)<br>
  31. * <pre>$handle->image_text_line_spacing = 3;</pre></li>
  32. * </ul>
To jest wersja lo-fi głównej zawartości. Aby zobaczyć pełną wersję z większą zawartością, obrazkami i formatowaniem proszę kliknij tutaj.
Invision Power Board © 2001-2025 Invision Power Services, Inc.