Witam. Mam problem z paskiem postępu, który nie działa. Skopane jest coś z nim, ale nie wiem co (linia 43-47)
Reszta działa, to znaczy wczutuje pliki, zmienia ich rozdzielczość i tworzy miniaturkę.

plik upload
  1. if(isset($_FILES['upload']) === true)
  2. {
  3.  
  4.  
  5.  
  6. for($i=0; $i<count($_FILES['upload']['name']); $i++)
  7. {
  8. if(is_file($_FILES['upload']['tmp_name'][$i]))
  9. {
  10.  
  11. define('DESTINATION', '../pliki/');
  12. define('RESIZEBY', 'w');
  13. define('RESIZETO', $liczbaszer);
  14. define('RESIZETOM', 300);
  15. define('QUALITY', 90);
  16.  
  17. require_once 'image.class.php';
  18.  
  19. $image = new Image($_FILES['upload']['tmp_name'][$i]);
  20. $plik=$_FILES['upload']['name'][$i];
  21. $ext = getExtension($plik);
  22.  
  23. $image->destination = DESTINATION.$ostid.".".$ext;
  24. $image->destinationm = DESTINATION.$ostid."m.".$ext;
  25.  
  26. $image->constraint = RESIZEBY;
  27. $image->size = RESIZETO;
  28. $image->sizem = RESIZETOM;
  29. $image->quality = QUALITY;
  30. $plik = $image->render($ext);
  31.  
  32. $plik = $ostid.".".$ext;
  33. $ostid++;
  34. }
  35. }
  36. echo 'Pliki graficzne zostały załadowane na serwer.';
  37. }
  38. ?>
  39.  
  40. <form action="upload.php" method="post" accept-charset="utf-8" enctype="multipart/form-data">
  41. <p>Wybierz grafiki:<input type="file" name="upload[]" multiple="true" id="idupload" onChange="listing();"/><p>
  42. <p>Szerokość:<input type="text" name="width" value=""/></p>
  43. <iframe id="progress_iframe" src="" style="display:none;" scrolling="no" frameborder="0"></iframe>
  44. <? $upload_id="1234"; ?>
  45. <input type="hidden" name="UPLOAD_IDENTIFIER" id="uid" value="1234">
  46. <p><input type="submit" value="Upload" onClick="function set() { f=document.getElementById('progress_iframe'); f.style.display='block'; f.src='uploadprogress.php?id=<?=$upload_id?>';} setTimeout(set);" /></p>
  47. </form>
  48.  
  49. <ul id="lista"><li></li></ul>
  50.  
  51. <!--lista plików do pobrania-->
  52.  
  53. <script type="text/javascript">
  54.  
  55. function listing() {
  56. var input = document.getElementById("idupload");
  57. var ul = document.getElementById("lista");
  58. while (ul.hasChildNodes()) {
  59. ul.removeChild(ul.firstChild);
  60. }
  61. for (var i = 0; i < input.files.length; i++) {
  62. var li = document.createElement("li");
  63. li.innerHTML = input.files[i].name;
  64. ul.appendChild(li);
  65. }
  66. if(!ul.hasChildNodes()) {
  67. var li = document.createElement("li");
  68. li.innerHTML = 'Nie wybrano żadnych plików';
  69. ul.appendChild(li);
  70. }
  71. }
  72. </script>



plik image.class.php:
  1. class Image
  2. {
  3. var $max_file_size = 2097152; #10MB
  4. var $allow_types = array('image/jpeg', 'image/png', 'image/gif');
  5. var $errors;
  6.  
  7. public $destination = '';
  8.  
  9. public $constraint = '';
  10.  
  11. public $size = '';
  12.  
  13. public $quality = '';
  14.  
  15. public $cropwidth = false;
  16. public $cropheight = false;
  17.  
  18. public $align;
  19.  
  20. public function __construct($imagefilepath)
  21. {
  22. $this->tmp_name = $imagefilepath;
  23.  
  24. $this->image_size = filesize($this->tmp_name);
  25.  
  26. $imagedata = getimagesize($this->tmp_name);
  27.  
  28.  
  29. $this->width = $imagedata[0]; // szerokosc obrazka wczytanego
  30. $this->height = $imagedata[1];
  31.  
  32. $this->type = $imagedata['mime'];
  33.  
  34. $this->is_valid = $this->is_valid_type();
  35. $this->is_valid = $this->is_valid_size();
  36.  
  37. }
  38.  
  39.  
  40. public function is_valid_type()
  41. {
  42. if (in_array($this->type, $this->allow_types))
  43. {
  44. return true;
  45. }
  46. else
  47. {
  48. return false;
  49. }
  50. }
  51.  
  52. public function is_valid_size()
  53. {
  54. if ($this->image_size['size'] <= $this->max_file_size)
  55. {
  56. return true;
  57. }
  58. else
  59. {
  60. return false;
  61. }
  62. }
  63.  
  64.  
  65. public function render($ext)
  66. {
  67. $destname = $this->destination;
  68. $destnamem = $this->destinationm;
  69. $constraint = $this->constraint;
  70. $new_side = $this->size; // wymiary
  71. $new_sidem = $this->sizem; // wymiary miniatórki
  72. $cropw = $this->cropwidth;
  73. $croph = $this->cropheight;
  74. $quality = $this->quality;
  75.  
  76. // echo"DESTNAME: $destname, DRSTNAMEM: $destnamem<br />";
  77.  
  78.  
  79. if ($constraint == "h")
  80. {
  81. $new_w = ($new_side / $this->height) * $this->width;
  82. $new_wm = ($new_sidem / $this->height) * $this->width; // M
  83. $new_h = $new_side;
  84. $new_hm = $new_sidem; // M
  85.  
  86. $canvasw = ($cropw!=false) ? $cropw : $new_w;
  87. $canvash = ($croph!=false) ? $croph : $new_h;
  88. $canvas = imagecreatetruecolor($canvasw, $canvash);
  89. // echo"tworze CANVAS H....";
  90.  
  91. $canvaswm = ($cropw!=false) ? $cropw : $new_wm; // M
  92. $canvashm = ($croph!=false) ? $croph : $new_hm; // M
  93. $canvasm = imagecreatetruecolor($canvaswm, $canvashm); // M
  94.  
  95. $x = ($cropw==false) ? 0 : -(($new_w - $cropw)/2);
  96. $y = ($croph==false) ? 0 : -(($new_h - $croph)/2);
  97.  
  98. $xm = ($cropw==false) ? 0 : -(($new_wm - $cropw)/2); // M
  99. $ym = ($croph==false) ? 0 : -(($new_hm - $croph)/2); // M
  100.  
  101.  
  102. }
  103. else if ($constraint == "w")
  104. {
  105. $new_h = ($new_side / $this->width) * $this->height;
  106. $new_w = $new_side;
  107.  
  108. $new_hm = ($new_sidem / $this->width) * $this->height; // M
  109. $new_wm = $new_sidem; //M
  110.  
  111. $canvasw = ($cropw!=false) ? $cropw : $new_w;
  112. $canvash = ($croph!=false) ? $croph : $new_h;
  113. $canvas = imagecreatetruecolor($canvasw, $canvash);
  114. // echo"tworze CANVAS W....";
  115.  
  116.  
  117. $canvaswm = ($cropw!=false) ? $cropw : $new_wm; // M
  118. $canvashm = ($croph!=false) ? $croph : $new_hm; //M
  119. $canvasm = imagecreatetruecolor($canvaswm, $canvashm); //M
  120.  
  121. $x = ($cropw==false) ? 0 : -(($new_w - $cropw)/2);
  122. $y = ($croph==false) ? 0 : -(($new_h - $croph)/2);
  123.  
  124. $xm = ($cropw==false) ? 0 : -(($new_wm - $cropw)/2);
  125. $ym = ($croph==false) ? 0 : -(($new_hm - $croph)/2);
  126. }
  127. else if ($constraint == "t")
  128. {
  129. if($this->height > $this->width)
  130. {
  131. $new_h = ($new_side / $this->width) * $this->height;
  132. $new_w = $new_side;
  133.  
  134. $new_hm = ($new_sidem / $this->width) * $this->height; //M
  135. $new_wm = $new_sidem; // M
  136.  
  137. $x = 0;
  138. $y = -(($new_h-$new_side)/2);
  139.  
  140. $xm = 0; //M
  141. $ym = -(($new_hm-$new_sidem)/2); //M
  142.  
  143. }
  144. else if($this->height <= $this->width)
  145. {
  146. $new_w = ($new_side / $this->height) * $this->width;
  147. $new_h = $new_side;
  148.  
  149. $new_wm = ($new_sidem / $this->height) * $this->width; // M
  150. $new_hm = $new_sidem; // M
  151.  
  152.  
  153. $x = -(($new_w-$new_side)/2);
  154. $y = 0;
  155.  
  156. $xm = -(($new_wm-$new_sidem)/2); //M
  157. $ym = 0; //M
  158.  
  159. }
  160.  
  161. $canvas = imagecreatetruecolor($new_side, $new_side);
  162. $canvasm = imagecreatetruecolor($new_sidem, $new_sidem); //M
  163. // echo"tworze CANVAS T....";
  164.  
  165. }
  166. else
  167. {
  168. $new_h = $this->height;
  169. $new_w = $this->width;
  170.  
  171. $new_hm = $this->height; // M
  172. $new_wm = $this->width; //M
  173.  
  174.  
  175. $x = $y = 0;
  176. $xm = $ym = 0; //M
  177.  
  178.  
  179. $canvas = imagecreatetruecolor($new_w, $new_h);
  180. $canvasm = imagecreatetruecolor($new_wm, $new_hm);//M
  181. // echo"tworze CANVAS T ELSE....";
  182.  
  183. }
  184.  
  185. switch($this->type)
  186. {
  187. case 'image/jpeg':
  188. $ic = imagecreatefromjpeg($this->tmp_name);
  189. break;
  190.  
  191. case 'image/gif':
  192. $ic = imagecreatefromgif($this->tmp_name);
  193. break;
  194.  
  195. case 'image/png':
  196. $ic = imagecreatefrompng($this->tmp_name);
  197. break;
  198. }
  199. if($canvas==FALSE) echo"CANVAS FALSE!<br />";
  200.  
  201.  
  202.  
  203. $test2=imagecopyResampled($canvasm,
  204. $ic,
  205. $x, $y, 0, 0,
  206. $new_wm, $new_hm,
  207. $this->width, $this->height); //M
  208. $test1=imagecopyResampled($canvas,
  209. $ic,
  210. $x, $y, 0, 0,
  211. $new_w, $new_h,
  212. $this->width, $this->height);
  213.  
  214. //if($test1==TRUE) $test1="TRUE"; else $test1="FALSE";
  215. //if($test2==TRUE) $test2="TRUE"; else $test2="FALSE";
  216.  
  217. //echo"TEST1: $test1, TEST2(miniat)= $test2<br />";
  218.  
  219.  
  220. if ($ext=='jpg' || $ext=='jpeg'){
  221. imagejpeg($canvasm, $destnamem, $quality); //M
  222. imagejpeg($canvas, $destname, $quality);
  223. }
  224. if ($ext=='gif'){
  225. imagegif($canvas, $destname);
  226. imagegif($canvasm, $destnamem); //M
  227. }
  228. if ($ext=='png'){
  229. imagegif($canvas, $destname, $quality);
  230. imagegif($canvasm, $destnamem, $quality); //M
  231. }
  232.  
  233.  
  234. imagedestroy($canvas);
  235. imagedestroy($canvasm);
  236. return $destname;
  237. }
  238.  
  239.  
  240. public function done()
  241. {
  242. unlink($this->tmp_name);
  243. }
  244.  
  245. }


uploadprogress.php
  1. <META HTTP-EQUIV='REFRESH' CONTENT='1;URL='>
  2. </head>
  3. Upload progress:<br />
  4. <?php
  5. if(!$_GET['uid']) die;
  6. $info = uploadprogress_get_info($_GET['uid']);
  7. $kbytes_total = round($info['bytes_total'] / 1024);
  8. $kbytes_uploaded = round($info['bytes_uploaded'] / 1024);
  9. echo $kbytes_uploaded.'/'.$kbytes_total.' KB';
  10. ?>
  11. </body>
  12. </html>