fantomel Posted September 20, 2009 Share Posted September 20, 2009 Hello i`ve build a small upload form with a thumbnail script in it but doesn't work and i don't know why can someone check it out please? upload.php <?php session_start(); if (!$_SESSION['rows']) $_SESSION['rows']=1; ?> <form action="do_upload.php" method="post" enctype="multipart/form-data" name="form" id="form"> <table width="800" border="1" align="center" cellpadding="3" cellspacing="2" bordercolor="#999999"> <?php for ($i=1; $i<=$_SESSION['rows']; $i++) { ?> <tr> <td bgcolor="#D6D6D6">Poza <?=$i;?>:</td> <td bgcolor="#D6D6D6"><input name="pic<?=$i;?>" type="file" id="pic<?=$i;?>" /></td> </tr> <?php } ?> <tr> <td width="150" bgcolor="#D6D6D6"><input name="Rows" type="submit" class="buton" id="Rows" value="+" /> <input name="Rows" type="submit" class="buton" id="Rows" value="-" /></td> <td width="650" bgcolor="#D6D6D6"><input name="Upload" type="submit" class="buton" id="Upload" value="Upload" /></td> </tr> </table> </form> do_upload.php <?php session_start(); if ($_POST['Rows']) { if ($_POST['Rows']=="+") $_SESSION['rows']++; if ($_POST['Rows']=="-") $_SESSION['rows']--; header("Location: upload.php"); exit; } if ($_POST['Upload']=="Upload") { for ($z=1; $z<=$_SESSION['rows']; $z++) { $curent="pic$z"; if ($_FILES[$curent]['name']!="") { $new_name="image_".md5(date("U")); $new_name_small="$new_name"."_thumbs.jpg"; $thumb_size=250; list($width, $height, $type) = getimagesize($_FILES[$curent]['tmp_name']); $type = image_type_to_extension($type); $img_file = "$new_name".".jpg"; $upload_file = $img_file.basename($_FILES[$curent]['$new_name']); move_uploaded_file($_FILES[$curent]['tmp_name'], $upload_file); $img_ratio=$width/$height; if ($img_ratio>1){ $new_width = ($thumb_size<$width)?$thumb_size:$width; $new_height =$new_width/$img_ratio; }else{ $new_height = ($thumb_size<$width)?$thumb_size:$height; $new_width = $new_height*$img_ratio; } if ($type==".jpeg") $source = imagecreatefromjpeg($upload_file); if ($type==".png") $source = imagecreatefrompng($upload_file); if ($type==".gif") $source = imagecreatefromgif($upload_file); $thumb = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($thumb, "$new_name_small" , 100); $poze.="$new_name, "; } sleep(1); } } ?> Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 20, 2009 Share Posted September 20, 2009 You say it is not working. What aspect is not working? The file upload? The thumb generation? Single or multiple uploads/thumbnails? Quote Link to comment Share on other sites More sharing options...
fantomel Posted September 20, 2009 Author Share Posted September 20, 2009 You say it is not working. What aspect is not working? The file upload? The thumb generation? Single or multiple uploads/thumbnails? sorry i`m just in hurry and i`m mad cuz it's not working forgot to tell what and how.. yes single // multiple upload // thumbail generation doesn't work and i get zip no error i don't know why ~X( Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 20, 2009 Share Posted September 20, 2009 add this to upload.php session_start(); error_reporting(E_ALL); Quote Link to comment Share on other sites More sharing options...
fantomel Posted September 20, 2009 Author Share Posted September 20, 2009 add this to upload.php session_start(); error_reporting(E_ALL); Notice: Undefined index: rows in C:\x\xampp\htdocs\test\upload.php on line 4 and for do_upload.php Notice: Undefined index: Rows in C:\x\xampp\htdocs\test\do_upload.php on line 5 Notice: Undefined index: pic1 in C:\x\xampp\htdocs\test\do_upload.php on line 16 Quote Link to comment Share on other sites More sharing options...
ozestretch Posted September 20, 2009 Share Posted September 20, 2009 <?php session_start(); if (isset($_POST['Rows'])) { if ($_POST['Rows']=="+") $_SESSION['rows']++; if ($_POST['Rows']=="-") $_SESSION['rows']--; header("Location: upload.php"); exit; } if (isset($_POST['Upload']) || $_POST['Upload']=="Upload") { for ($z=1; $z<=$_SESSION['rows']; $z++) { $curent="pic$z"; if (isset($_FILES[$curent]['name']) || $_FILES[$curent]['name']!="") { $new_name="image_".md5(date("U")); $new_name_small="$new_name"."_thumbs.jpg"; $thumb_size=250; list($width, $height, $type) = getimagesize($_FILES[$curent]['tmp_name']); $type = image_type_to_extension($type); $img_file = "$new_name".".jpg"; $upload_file = $img_file.basename($_FILES[$curent]['$new_name']); move_uploaded_file($_FILES[$curent]['tmp_name'], $upload_file); $img_ratio=$width/$height; if ($img_ratio>1){ $new_width = ($thumb_size<$width)?$thumb_size:$width; $new_height =$new_width/$img_ratio; }else{ $new_height = ($thumb_size<$width)?$thumb_size:$height; $new_width = $new_height*$img_ratio; } if ($type==".jpeg") $source = imagecreatefromjpeg($upload_file); if ($type==".png") $source = imagecreatefrompng($upload_file); if ($type==".gif") $source = imagecreatefromgif($upload_file); $thumb = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($thumb, "$new_name_small" , 100); $poze.="$new_name, "; } sleep(1); } } if(isset($poze)){ echo $poze; } ?> then of course, check the folder to see if it did actually upload. Quote Link to comment Share on other sites More sharing options...
fantomel Posted September 20, 2009 Author Share Posted September 20, 2009 <?php session_start(); if (isset($_POST['Rows'])) { if ($_POST['Rows']=="+") $_SESSION['rows']++; if ($_POST['Rows']=="-") $_SESSION['rows']--; header("Location: upload.php"); exit; } if (isset($_POST['Upload']) || $_POST['Upload']=="Upload") { for ($z=1; $z<=$_SESSION['rows']; $z++) { $curent="pic$z"; if (isset($_FILES[$curent]['name']) || $_FILES[$curent]['name']!="") { $new_name="image_".md5(date("U")); $new_name_small="$new_name"."_thumbs.jpg"; $thumb_size=250; list($width, $height, $type) = getimagesize($_FILES[$curent]['tmp_name']); $type = image_type_to_extension($type); $img_file = "$new_name".".jpg"; $upload_file = $img_file.basename($_FILES[$curent]['$new_name']); move_uploaded_file($_FILES[$curent]['tmp_name'], $upload_file); $img_ratio=$width/$height; if ($img_ratio>1){ $new_width = ($thumb_size<$width)?$thumb_size:$width; $new_height =$new_width/$img_ratio; }else{ $new_height = ($thumb_size<$width)?$thumb_size:$height; $new_width = $new_height*$img_ratio; } if ($type==".jpeg") $source = imagecreatefromjpeg($upload_file); if ($type==".png") $source = imagecreatefrompng($upload_file); if ($type==".gif") $source = imagecreatefromgif($upload_file); $thumb = imagecreatetruecolor($new_width, $new_height); imagecopyresampled($thumb, $source, 0, 0, 0, 0, $new_width, $new_height, $width, $height); imagejpeg($thumb, "$new_name_small" , 100); $poze.="$new_name, "; } sleep(1); } } if(isset($poze)){ echo $poze; } ?> then of course, check the folder to see if it did actually upload. still didn't work :| Quote Link to comment Share on other sites More sharing options...
raccoon Posted September 20, 2009 Share Posted September 20, 2009 I think there is something wrong around here: $img_file = "$new_name".".jpg"; $upload_file = $img_file.basename($_FILES[$curent]['$new_name']); Whether it be the that $upload_file will equal something like "something.jpgthensomemorestuff" and/or that $new_name is in single quotes Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.