petrosa Posted June 12, 2009 Share Posted June 12, 2009 Hello, I have just transfered my webpage to another server, and now the script that uploads an image file doesnt work. All i get is the "Sorry, there was a problem uploading your file." from when the image fails to trasfer. I thought it might be permissions error, but its a windows based server where chmod is not possible. I tried to echo $_FILES['error'], but i get a '0' which means "There is no error, the file uploaded with success". The error is printed when trying to move (move_uploaded_file()) the file to the directory i want. What might be the source of the problem? here is the code $rand1 = rand(); $target = dirname( __FILE__ )."/photos/"; $target1 = $target . $rand1 . basename( $_FILES['photo1']['name']); if (($_FILES['photo1']['name']) == ""){ $pic1="default.gif"; } else{ $pic1 = $rand1 . basename( $_FILES['photo1']['name']); if (!getimagesize($_FILES['photo1']['tmp_name'])){ echo "Invalid Image File..."; exit(); } } $name = $_REQUEST['name']; $telephone = $_REQUEST['telephone']; $address = $_REQUEST['address']; $lat = $_REQUEST['lat']; $lng = $_REQUEST['lng']; $date=time(); if (($_FILES['photo1']['name']) != ""){ //Writes the photo to the server if(move_uploaded_file($_FILES['photo1']['tmp_name'], $target1)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your nformation has been added to the directory"; //create thumbanail $n_width=100; // thumbanil width $n_height=100; // thumbnail height $thumbs = "thumbnails/"; $thumbs = $thumbs . $rand1 . basename( $_FILES['photo1']['name']); //if($_FILES['photo1'][type]=="image/jpeg"){ $im=ImageCreateFromJPEG($target1); $width=ImageSx($im); // Original picture width is stored $height=ImageSy($im); // Original picture height is stored $newimage=imagecreatetruecolor($n_width,$n_height); imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height); ImageJpeg($newimage,$thumbs); //chmod("$thumbs",0777); //} // end thumbnail creation } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } } Any help appreciated Quote Link to comment Share on other sites More sharing options...
waynew Posted June 12, 2009 Share Posted June 12, 2009 Have you got error reporting set to on? Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 12, 2009 Share Posted June 12, 2009 What does putting the following debugging code immediately after your first opening <?php tag give - ini_set("display_errors", "1"); error_reporting(E_ALL); echo "<pre>"; echo "FILES:"; print_r($_FILES); echo "</pre>"; Quote Link to comment Share on other sites More sharing options...
petrosa Posted June 12, 2009 Author Share Posted June 12, 2009 What does putting the following debugging code immediately after your first opening <?php tag give - ini_set("display_errors", "1"); error_reporting(E_ALL); echo "<pre>"; echo "FILES:"; print_r($_FILES); echo "</pre>"; i did that and i got this FILES:Array ( [photo1] => Array ( [name] => massa.jpg [type] => image/jpeg [tmp_name] => C:\WINNT\Temp\phpB0.tmp [error] => 0 [size] => 23314 ) [photo2] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [photo3] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) ) Quote Link to comment Share on other sites More sharing options...
ldougherty Posted June 12, 2009 Share Posted June 12, 2009 Odd that you did not get an error but I see the script is using a temp directory of C:\WINNT\Temp\phpB0.tmp More than likely you do not have permission to write to this directory, ask your hosting company to adjust the value of upload_tmp_dir to a valid temp directory on your site that the IUSR has permissions to write to. Quote Link to comment Share on other sites More sharing options...
petrosa Posted June 12, 2009 Author Share Posted June 12, 2009 What does putting the following debugging code immediately after your first opening <?php tag give - ini_set("display_errors", "1"); error_reporting(E_ALL); echo "<pre>"; echo "FILES:"; print_r($_FILES); echo "</pre>"; i did that and i got this FILES:Array ( [photo1] => Array ( [name] => massa.jpg [type] => image/jpeg [tmp_name] => C:\WINNT\Temp\phpB0.tmp [error] => 0 [size] => 23314 ) [photo2] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) [photo3] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) ) The same code that i pasted at start, is applied to 3 different files, exactly the same Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 12, 2009 Share Posted June 12, 2009 If the posted code for photo1 gives no php errors (assuming your code is not changing the error_reporting/display_errors settings itself), and you get your 'Sorry, there was a problem uploading your file' for that data, then about the only possible cause is if the move_uploaded_file() function has been disabled. What does a phpinfo(); statement show for the disable_functions setting? Quote Link to comment Share on other sites More sharing options...
petrosa Posted June 12, 2009 Author Share Posted June 12, 2009 Odd that you did not get an error but I see the script is using a temp directory of C:\WINNT\Temp\phpB0.tmp More than likely you do not have permission to write to this directory, ask your hosting company to adjust the value of upload_tmp_dir to a valid temp directory on your site that the IUSR has permissions to write to. If i dont have permision to upload to that directory, wouldnt i get an error before i try to move the file? Uploading the file is fine, but cant write it to C:\WINNT\Temp\phpB0.tmp ? Not sure how the whole upload is handled by php. In any case, i will ask the administrator to change the upload_tmp_dir and see how it goes. Quote Link to comment Share on other sites More sharing options...
petrosa Posted June 12, 2009 Author Share Posted June 12, 2009 If the posted code for photo1 gives no php errors (assuming your code is not changing the error_reporting/display_errors settings itself), and you get your 'Sorry, there was a problem uploading your file' for that data, then about the only possible cause is if the move_uploaded_file() function has been disabled. What does a phpinfo(); statement show for the disable_functions setting? phpinfo() shows me this disable_functions no value no value Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 12, 2009 Share Posted June 12, 2009 Your statement of what you are getting does not match the data and posted code. You would need to post your full code for anyone to have a chance at helping with what it is doing. Quote Link to comment Share on other sites More sharing options...
petrosa Posted June 12, 2009 Author Share Posted June 12, 2009 here is the full script <?php require("dbinfo.php"); $rand1 = rand(); $rand2 = rand(); $rand3 = rand(); $target = "photos/"; $target1 = $target .$rand1. basename( $_FILES['photo1']['name']); $target2 = $target .$rand2. basename( $_FILES['photo2']['name']); $target3 = $target .$rand3. basename( $_FILES['photo3']['name']); if (($_FILES['photo1']['name']) == ""){ $pic1="default.gif"; } else { $pic1 = $rand1 . basename( $_FILES['photo1']['name']); if (!getimagesize($_FILES['photo1']['tmp_name'])) { echo "Invalid Image File..."; exit(); } } if (($_FILES['photo2']['name']) == ""){ $pic2="default.gif"; } else { $pic2 = $rand2 . basename( $_FILES['photo2']['name']); if (!getimagesize($_FILES['photo2']['tmp_name'])) { echo "Invalid Image File..."; exit(); } } if (($_FILES['photo3']['name']) == ""){ $pic3="default.gif"; } else { $pic3 = $rand3 . basename( $_FILES['photo3']['name']); if (!getimagesize($_FILES['photo3']['tmp_name'])) { echo "Invalid Image File..."; exit(); } } $name = $_REQUEST['name']; $telephone = $_REQUEST['telephone']; $address = $_REQUEST['address']; $lat = $_REQUEST['lat']; $lng = $_REQUEST['lng']; $date = time(); /* if (!isset($_REQUEST['name']) || !isset($_REQUEST['telephone']) || !isset($_REQUEST['address']) || !isset($_REQUEST['lat']) || !isset($_REQUEST['lng']) ) { header( "http://www.blahbla.com/scripts/login_success.php" ); echo "test"; } elseif (empty($name) || empty($telephone) || empty($address) || empty($lat) || empty($lng)) { header( "Location: http://www.blahbla.com/error.html" ); } else { */ if (($_FILES['photo1']['name']) != ""){ //Writes the photo to the server if(move_uploaded_file($_FILES['photo1']['tmp_name'], $target1)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; //create thumbanail $n_width=100; // thumbnail width $n_height=100; // thumbnail height $thumbs = "thumbnails/"; $thumbs = $thumbs . $rand1 . basename( $_FILES['photo1']['name']); $thumbs = $thumbs; //if($_FILES['photo1'][type]=="image/jpeg"){ $im=ImageCreateFromJPEG($target1); $width=ImageSx($im); // Original picture width is stored $height=ImageSy($im); // Original picture height is stored $newimage=imagecreatetruecolor($n_width,$n_height); imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height); ImageJpeg($newimage,$thumbs); //chmod("$thumbs",0777); //} // end thumbnail creation } else{ //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } } if (($_FILES['photo2']['name']) != ""){ //Writes the photo to the server if(move_uploaded_file($_FILES['photo2']['tmp_name'], $target2)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; //create thumbanail $n_width=100; // thumbnail width $n_height=100; // thumbnail height $thumbs = "thumbnails/"; $thumbs = $thumbs . $rand2 . basename( $_FILES['photo2']['name']); $thumbs = $thumbs; //if($_FILES['photo2'][type]=="image/jpeg"){ $im=ImageCreateFromJPEG($target2); $width=ImageSx($im); // Original picture width is stored $height=ImageSy($im); // Original picture height is stored $newimage=imagecreatetruecolor($n_width,$n_height); imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height); ImageJpeg($newimage,$thumbs); //chmod("$thumbs",0777); //} // end thumbnail creation } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } } if (($_FILES['photo3']['name']) != ""){ //Writes the photo to the server if(move_uploaded_file($_FILES['photo3']['tmp_name'], $target3)) { //Tells you if its all ok echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded, and your information has been added to the directory"; //create thumbanail $n_width=100; // thumbnail width $n_height=100; // thumbnail height $thumbs = "thumbnails/"; $thumbs = $thumbs . $rand3 . basename( $_FILES['photo3']['name']); $thumbs = $thumbs; //if($_FILES['photo3'][type]=="image/jpeg"){ $im=ImageCreateFromJPEG($target3); $width=ImageSx($im); // Original picture width is stored $height=ImageSy($im); // Original picture height is stored $newimage=imagecreatetruecolor($n_width,$n_height); imageCopyResized($newimage,$im,0,0,0,0,$n_width,$n_height,$width,$height); ImageJpeg($newimage,$thumbs); //chmod("$thumbs",0777); //} // end thumbnail creation } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } } $con = mysql_connect($host, $username, $password); if (!$con) { die('Could not connect: ' . mysql_error()); } mysql_select_db($database, $con); //mysql_query("SET NAMES 'utf8'", $con); /*$sql="INSERT INTO marker (name, address, arDomation, minPrice, maxPrice, minArea, maxArea, age, telephone, email, details, lat, lng, nisi, type, photo, date, approved) VALUES ('$_POST[name]','$_POST[address]','$_POST[arDomation]','$_POST[minPrice]','$_POST[maxPrice]','$_POST[minArea]','$_POST[maxArea]','$_POST[age]','$_POST[telephone]','$_POST[email]','$_POST[details]','$_POST[lat]','$_POST[lng]','$nisi','$_POST[type]','$pic','$date',0)"; */ $sql="INSERT INTO ".$_POST[nisi]." (name, address, arDomation, minPrice, minArea, age, telephone, email, details, lat, lng, type, photo, photo2, photo3, date, approved, dist1, dist2, dist3, dist4, dist5) VALUES ('$_POST[name]','$_POST[address]','$_POST[arDomation]','$_POST[minPrice]','$_POST[minArea]','$_POST[age]','$_POST[telephone]','$_POST[email]','$_POST[details]','$_POST[lat]','$_POST[lng]','$_POST[type]','$pic1','$pic2','$pic3','$date',0,'$_POST[dist1]','$_POST[dist2]','$_POST[dist3]','$_POST[dist4]','$_POST[dist5]')"; if (!mysql_query($sql,$con)){ die('Error: ' . mysql_error()); } mysql_close($con); //send email function contains_newlines($str_to_test) { if(preg_match("/(%0A|%0D|\\n+|\\r+)/i", $str_to_test) != 0) { exit; } } switch ($_POST['nisi']){ case 'Lesvos' : $to = "somemail@yahoo.gr"; break; case 'Limnos' : $to = "somemail@yahoo.gr"; break; case 'Rodos' : $to = "somemail@yahoo.gr"; break; case 'Samos' : $to = "somemail@yahoo.gr"; break; case 'Syros' : $to = "somemail@yahoo.gr"; break; case 'Chios' : $to = "somemail@yahoo.gr"; break; } $subject = '=?utf-8?b?' . base64_encode('Νέα Εισαγωγή Εγγραφής Ενοικιαζόμενου!') . '?='; $name_field = $_POST['name']; if ($_POST['email'] != ""){ $email_field = $_POST['email']; } else { $email_field = '=?utf-8?b?' . base64_encode('Άγνωστο Email') . '?='; } ini_set("sendmail_from", $email_field); $message = "Μία Νέα Εγγραφή έχει προστεθεί στη βάση δεδομένων. Παρακαλώ όπως την επισκοπίσετε το συντομότερο."; $body = "From: $name_field\n E-Mail: $email_field\n Message:\n $message"; if($_SERVER['REQUEST_METHOD'] != "POST"){ echo "Unauthorized attempt to access page.<br />"; echo "here you must use the exit or die php functions to finish the script.<br /><br />"; exit; } contains_newlines($email); mail($to, $subject, $body); header("location:http://www.blahblah.com/thanksInsert.php"); //} ?> this code was working fine on my previous host, cant seem to find the problem now :\ edit: some characters dont show because they are greek Quote Link to comment Share on other sites More sharing options...
ldougherty Posted June 12, 2009 Share Posted June 12, 2009 when you outputted the phpinfo what is the value of upload_tmp_dir Quote Link to comment Share on other sites More sharing options...
PFMaBiSmAd Posted June 12, 2009 Share Posted June 12, 2009 I'm going to guess that the missing clue here is that the following code was never put in (it's certainly not in the posted "full" script) - ini_set("display_errors", "1"); error_reporting(E_ALL); Edit: I'm also going to guess that the posted $_FILES data for massa.jpg is not or did not cause the "Sorry, there was a problem uploading your file." error to be displayed. Quote Link to comment Share on other sites More sharing options...
petrosa Posted June 12, 2009 Author Share Posted June 12, 2009 Dont know what the hell just happened, the script started working now as intended, with no changes at all. Dont know if my host changed something, because i have been bugging him for 3 days now about changes. Files are being upload ok and thumbnails are created. I will ask the host if he did anything, because this still makes me scratch my head :\ Anyway, thank you all for the help, afterall i still learned 2-3 new stuff from this. Hope this doesnt brake again, so much frustration when changing hosts Thanks again 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.