regoch Posted November 3, 2011 Share Posted November 3, 2011 I have this code for upload single image on my page and been working for sometime, but today stop working. And my multi upload code stop working to. I check permision of folder and is 775. Single image upload. This is a error code Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /home/epakosta/public_html/admin/novosti-unos-slike.php on line 143 Warning: copy() [function.copy]: Unable to access in /home/epakosta/public_html/admin/novosti-unos-slike.php on line 158 Warning: copy() [function.copy]: Unable to access in /home/epakosta/public_html/admin/novosti-unos-slike.php on line 159 <?php //define a maxim size for the uploaded images define ("MAX_SIZE","500"); // define the width and height for the thumbnail // note that theese dimmensions are considered the maximum dimmension and are not fixed, // because we have to keep the image ratio intact or it will be deformed define ("WIDTH","150"); //set here the width you want your thumbnail to be define ("HEIGHT","150"); //set here the height you want your thumbnail to be. define ("WIDTH2","700"); //set here the width you want your thumbnail to be define ("HEIGHT2","933");// set here the height you want your thumbnail to be. // this is the function that will create the thumbnail image from the uploaded image // the resize will be done considering the width and height defined, but without deforming the image function make_thumb($img_name,$filename,$new_w,$new_h){ //get image extension. $ext=getExtension($img_name); //creates the new image using the appropriate function from gd library if(!strcmp("jpg",$ext) || !strcmp("jpeg",$ext)) $src_img=imagecreatefromjpeg($img_name); if(!strcmp("png",$ext)) $src_img=imagecreatefrompng($img_name); if(!strcmp("gif",$ext)) $src_img=imagecreatefromgif($img_name); //gets the dimmensions of the image $old_x=imageSX($src_img); $old_y=imageSY($src_img); // next we will calculate the new dimmensions for the thumbnail image // the next steps will be taken: // 1. calculate the ratio by dividing the old dimmensions with the new ones // 2. if the ratio for the width is higher, the width will remain the one define in WIDTH variable // and the height will be calculated so the image ratio will not change // 3. otherwise we will use the height ratio for the image // as a result, only one of the dimmensions will be from the fixed ones $ratio1=$old_x/$new_w; $ratio2=$old_y/$new_h; if($ratio1>$ratio2) { $thumb_w=$new_w; $thumb_h=$old_y/$ratio1; }else{ $thumb_h=$new_h; $thumb_w=$old_x/$ratio2; } // we create a new image with the new dimmensions $dst_img=ImageCreateTrueColor($thumb_w,$thumb_h); // resize the big image to the new created one imagecopyresampled($dst_img,$src_img,0,0,0,0,$thumb_w,$thumb_h,$old_x,$old_y); // output the created image to the file. Now we will have the thumbnail into the file named by $filename if(!strcmp("png",$ext)) imagepng($dst_img,$filename); else imagejpeg($dst_img,$filename); if (!strcmp("gif",$ext)) imagegif($dst_img,$filename); //destroys source and destination images. imagedestroy($dst_img); imagedestroy($src_img); } // This function reads the extension of the file. // It is used to determine if the file is an image by checking the extension. function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } // This variable is used as a flag. The value is initialized with 0 (meaning no error found) //and it will be changed to 1 if an error occures. If the error occures the file will not be uploaded. $errors=0; // checks if the form has been submitted if(isset($_POST['Submit'])){ //reads the name of the file the user submitted for uploading $image=$_FILES['cons_image']['name']; // if it is not empty if ($image) { // get the original name of the file from the clients machine $filename = stripslashes($_FILES['cons_image']['name']); // get the extension of the file in a lower case format $extension = getExtension($filename); $extension = strtolower($extension); // if it is not a known extension, we will suppose it is an error, print an error message //and will not upload the file, otherwise we continue if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { echo 'Nepoznata ekstenzija! Molimo upotrijebite samo .gif, .jpg ili .png datoteke.'; $errors=1; }else{ // get the size of the image in bytes // $_FILES[\'image\'][\'tmp_name\'] is the temporary filename of the file in which //the uploaded file was stored on the server $size=getimagesize($_FILES['cons_image']['tmp_name']); $sizekb=filesize($_FILES['cons_image']['tmp_name']); //compare the size with the maxim size we defined and print error if bigger if ($sizekb > MAX_SIZE*4096) { echo 'Slika je veća od 4 mb!'; $errors=1; } $rand= rand(0000000000, 9999999999); //we will give an unique name, for example a random number $image_name='RGallery_'.$rand.'.'.$extension; //the new name will be containing the full path where will be stored (images folder) $consname="images/".$image_name; //change the image/ section to where you would like the original image to be stored $consname2="images/thumbs/".$image_name; //change the image/thumb to where you would like to store the new created thumb nail of the image $copied = copy($_FILES['cons_image']['tmp_name'], $consname); $copied = copy($_FILES['cons_image']['tmp_name'], $consname2); $novost_id=$_GET['novost_id']; $sql="UPDATE novosti SET novost_slika='$image_name' WHERE novost_id='$novost_id'"; $query = mysql_query($sql)or die(mysql_error()); //$sql="UPDATE users SET photo_1= '$consname' WHERE id= '1'" or die(mysql_error()); //$query = mysql_query($sql)or die(mysql_error()); //$sql="UPDATE users SET photo_2= '$consname2' WHERE id= '1'" or die(mysql_error()); //$query = mysql_query($sql)or die(mysql_error()); //we verify if the image has been uploaded, and print error instead if (!$copied) { echo 'Nije uspjelo!'; $errors=1; }else{ // the new thumbnail image will be placed in images/thumbs/ folder $thumb_name=$consname2 ; // call the function that will create the thumbnail. The function will get as parameters //the image name, the thumbnail name and the width and height desired for the thumbnail $thumb=make_thumb($consname,$thumb_name,WIDTH,HEIGHT); $thumb=make_thumb($consname,$consname,WIDTH2,HEIGHT2); } } } } //If no errors registred, print the success message and how the thumbnail image created if(isset($_POST['Submit']) && !$errors) { echo "Slika uspješno unesena!"; echo '<br /><img src="images/thumbs/'.$image_name.'"><br />'; echo $lastid; } ?> <h4>Dozvoljen je unos slika veličine do 4 mb!</h4> <form method="post" enctype="multipart/form-data" action=""> <table cellspacing="2" cellpadding="2" border="0"> <tr> <th align="right" style="width:150px">Upload slike: </th> <td><input type="file" name="cons_image" id="cons_image" /></td> </tr> <tr> <th></th> <td><input type="submit" name="Submit" id="Submit" value="Pošalji" /> </td> </tr> </table> </form> Multi image upload my error code Warning: imagecreatefromjpeg() [function.imagecreatefromjpeg]: Filename cannot be empty in /home/epakosta/public_html/admin/galerije-unos-slike.php on line 114 Warning: getimagesize() [function.getimagesize]: Filename cannot be empty in /home/epakosta/public_html/admin/galerije-unos-slike.php on line 130 Warning: Division by zero in /home/epakosta/public_html/admin/galerije-unos-slike.php on line 134 Warning: imagecreatetruecolor() [function.imagecreatetruecolor]: Invalid image dimensions in /home/epakosta/public_html/admin/galerije-unos-slike.php on line 135 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/epakosta/public_html/admin/galerije-unos-slike.php on line 142 Warning: imagecopyresampled(): supplied argument is not a valid Image resource in /home/epakosta/public_html/admin/galerije-unos-slike.php on line 144 Warning: imagejpeg(): supplied argument is not a valid Image resource in /home/epakosta/public_html/admin/galerije-unos-slike.php on line 158 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/epakosta/public_html/admin/galerije-unos-slike.php on line 172 Warning: imagedestroy(): supplied argument is not a valid Image resource in /home/epakosta/public_html/admin/galerije-unos-slike.php on line 173 multiupload script <?php $change=""; $abc=""; define ("MAX_SIZE","4096"); function getExtension($str) { $i = strrpos($str,"."); if (!$i) { return ""; } $l = strlen($str) - $i; $ext = substr($str,$i+1,$l); return $ext; } $errors=0; $slike = array('file', 'file1', 'file2', 'file3', 'file4'); if($_SERVER["REQUEST_METHOD"] == "POST") { // $image =$_FILES["file"]["name"]; // $uploadedfile = $_FILES['file']['tmp_name']; $filearray = array(); $filearray1 = array(); $k=0; foreach($slike as $slika){ $image =$_FILES[$slika]["name"]; $uploadedfile = $_FILES[$slika]['tmp_name']; if ($image) { $filename = stripslashes($_FILES[$slika]['name']); $extension = getExtension($filename); $extension = strtolower($extension); if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif")) { $change='<div class="msgdiv">Unknown Image extension </div> '; $errors=1; } else { $size=filesize($_FILES[$slika]['tmp_name']); if ($size > MAX_SIZE*4096) { $change='<div class="msgdiv">Slika je veća od 4096kb!</div> '; $errors=1; } if($extension=="jpg" || $extension=="jpeg" ) { $uploadedfile = $_FILES[$slika]['tmp_name']; $src = imagecreatefromjpeg($uploadedfile); } else if($extension=="png") { $uploadedfile = $_FILES[$slika]['tmp_name']; $src = imagecreatefrompng($uploadedfile); } else { $src = imagecreatefromgif($uploadedfile); } echo $scr; list($width,$height)=getimagesize($uploadedfile); $newwidth=700; $newheight=($height/$width)*$newwidth; $tmp=imagecreatetruecolor($newwidth,$newheight); $newwidth1=190; $newheight1=140; $tmp1=imagecreatetruecolor($newwidth1,$newheight1); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); imagecopyresampled($tmp1,$src,0,0,0,0,$newwidth1,$newheight1,$width,$height); //$filename = "images/". $_FILES['file']['name']; //$filename1 = "images/small". $_FILES['file']['name']; $rand = rand(0000000000, 9999999999); $image_name=(date("dmY")+$k).'_'.$rand.'.'.$extension; $filename = "../slike/".$image_name; $filename1 = "../slike/thumbnails/".$image_name; $filename3 = $image_name; $filename4 = $image_name; $id_galerije = $_GET['id_galerije']; imagejpeg($tmp,$filename,100); imagejpeg($tmp1,$filename1,100); $filearray[$k]= $filename3; $filearray1[$k]= $filename4; $filearray2[$k]= $id_galerije; $k++; // 3. Perform database query mysql_query("INSERT INTO slike set picture_name='$filename3', picture_name1='$filename4', id_galerije='$id_galerije'"); echo '<br /><img src="../slike/thumbnails/'.$filename4.'"><br />'; imagedestroy($src); imagedestroy($tmp); imagedestroy($tmp1); }} } } // If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { if ($filename3==""){ echo " <table width='400px' align='center' cellspacing='0'> <tr bgcolor='#E6e6e6' height='26'> <td align='center' width='100%' colspan='2'><strong>Potvrda</strong></td> </tr> <tr bgcolor='#F6f6f6'> <td align='center' style='border-left:#E6e6e6 1px solid;border-bottom:#E6e6e6 1px solid;'><img src='images/warning.png'></td> <td align='center' width='80'% style='border-right:#E6e6e6 1px solid;border-bottom:#E6e6e6 1px solid;'><strong>Slike nisu unešene.</strong></td> </tr> </table><br />"; } else{ echo " <table width='400px' align='center' cellspacing='0'> <tr bgcolor='#E6e6e6' height='26'> <td align='center' width='100%' colspan='2'><strong>Potvrda</strong></td> </tr> <tr bgcolor='#F6f6f6'> <td align='center' style='border-left:#E6e6e6 1px solid;border-bottom:#E6e6e6 1px solid;'><img src='images/valid.png'></td> <td align='center' width='80'% style='border-right:#E6e6e6 1px solid;border-bottom:#E6e6e6 1px solid;'><strong>Slike uspješno unesene.</strong></td> </tr> </table><br />"; } } /*If no errors registred, print the success message if(isset($_POST['Submit']) && !$errors) { // mysql_query("update {$prefix}users set img='$big',img_small='$small' where user_id='$user'"); $change=' <div class="msgdiv">Image Uploaded Successfully!</div>'; }*/ ?> Quote Link to comment https://forums.phpfreaks.com/topic/250402-upload-image-error-on-two-script/ Share on other sites More sharing options...
PFMaBiSmAd Posted November 3, 2011 Share Posted November 3, 2011 Your code is not checking if the upload worked before accessing the uploaded file information. You need some upload error checking, reporting/logging, and error recover logic in your code. For debugging purposes, to see what exactly is in the $_FILES information, add the following lines of code to your processing page - echo "<pre>"; echo "FILES:"; print_r($_FILES); echo "</pre>"; Quote Link to comment https://forums.phpfreaks.com/topic/250402-upload-image-error-on-two-script/#findComment-1284766 Share on other sites More sharing options...
regoch Posted November 3, 2011 Author Share Posted November 3, 2011 This is what i get on single image upload form FILES:Array( [cons_image] => Array ( [name] => PXL_111102_2188.jpg [type] => [tmp_name] => [error] => 8 [size] => 0 ) ) and this on multiupload form FILES:Array ( [file] => Array ( [name] => PXL_111102_2188.jpg [type] => [tmp_name] => [error] => 8 [size] => 0 ) [file1] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [file2] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [file3] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [file4] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) ) Quote Link to comment https://forums.phpfreaks.com/topic/250402-upload-image-error-on-two-script/#findComment-1284768 Share on other sites More sharing options...
PFMaBiSmAd Posted November 3, 2011 Share Posted November 3, 2011 The upload error number is 8. Unfortunately, there is little documentation for the meaning, but it is likely that you have the Suhosin hardened php patch installed on your server (or newly installed on your server) and it is what stopped the upload from working. Quote Link to comment https://forums.phpfreaks.com/topic/250402-upload-image-error-on-two-script/#findComment-1284782 Share on other sites More sharing options...
regoch Posted November 3, 2011 Author Share Posted November 3, 2011 I will try to send mail to hosting company! Quote Link to comment https://forums.phpfreaks.com/topic/250402-upload-image-error-on-two-script/#findComment-1284793 Share on other sites More sharing options...
regoch Posted November 5, 2011 Author Share Posted November 5, 2011 It was hosting company problem. I contact then I problem was solved. Quote Link to comment https://forums.phpfreaks.com/topic/250402-upload-image-error-on-two-script/#findComment-1285201 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.