Dave2136 Posted March 11, 2011 Share Posted March 11, 2011 Hi I am really frustrated because I got my php code working fine and then I had to make some minor changes to my html form and now the php is not working. I am reciec=ving this message: Warning: move_uploaded_file(upload/carey.bmp) [function.move-uploaded-file]: failed to open stream: No such file or directory in /home/content/19/6550319/html/ipad/listing.php on line 35 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/tmp/phpIEUQLo' to 'upload/carey.bmp' in /home/content/19/6550319/html/ipad/listing.php on line 35 Sorry, there was a problem uploading your file.03/10/11 : 20:50:08 I wrote it twice because it keeps coming out twice. I guess it means that it cant upload the image because there is no image but I really dont understand why. I havent changed the image part of the form. Does anyone have any ideas? It is much appreciated. Here is the code <?php //This is the directory where images will be saved $target = "upload/"; $target = $target . basename( $_FILES['photo']['name']); //This gets all the other information from the form $price=$_POST['price']; $pic=($_FILES['photo']['name']); $pic2=($_FILES['phototwo']['name']); $pic3=($_FILES['photothree']['name']); $pic4=($_FILES['photofour']['name']); $description=$_POST['iPadDescription']; $condition=$_POST['condition']; $gig=$_POST['giga']; $yesg=$_POST['yesg']; $fname=$_POST['firstName']; $lname=$_POST['lastName']; $email=$_POST['email']; // Connects to your Database mysql_connect ("taken out for security", "taken out", "taken out") or die(mysql_error()) ; mysql_select_db("taken out") or die(mysql_error()) ; //Writes the information to the database mysql_query("INSERT INTO ipadlist (price,photo,phototwo,photothree,photofour,iPadDescription,condition,giga,yesg,firstName,lastName,email) VALUES ('$price', '$pic', '$pic2', '$pic3', '$pic4', '$description', '$condition', '$gig', '$yesg', '$fname', '$lname', '$email')") ; //Writes the photo to the server if(move_uploaded_file($_FILES['photo']['tmp_name'], $target)) { //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"; } else { //Gives and error if its not echo "Sorry, there was a problem uploading your file."; } echo date("m/d/y : H:i:s", time()) ?> Quote Link to comment https://forums.phpfreaks.com/topic/230302-keep-receiving-a-failed-to-open-stream-for-image-error/ Share on other sites More sharing options...
Mahngiel Posted March 11, 2011 Share Posted March 11, 2011 why are you using 'basename' as an array for $_FILES? I have yet to see that around. Quote Link to comment https://forums.phpfreaks.com/topic/230302-keep-receiving-a-failed-to-open-stream-for-image-error/#findComment-1186010 Share on other sites More sharing options...
jcbones Posted March 11, 2011 Share Posted March 11, 2011 You need to add a lot of error checking before trying to move the file. If there was an error with the upload, then of course the file wouldn't exist in the tmp folder. Therefore, move_uploaded_file() would fail. Take a look at this upload function. It is old. function uploadImage($setWidth = 1000, $setHeight = 1000, $filepath = 'upload/') { $content = NULL; if($_FILES["file"]["size"] > 900000) { $error[] = "File is to large, submit a smaller image!"; } elseif(empty($_FILES["file"]["name"])) { $error[] = "No File Uploaded!"; } else { if ((($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/jpeg") || ($_FILES["file"]["type"] == "image/pjpeg") || ($_FILES["file"]["type"] == "image/png") || ($_FILES["file"]["type"] == "image/jpg") || ($_FILES["file"]["type"] == "image/x-png")) && ($_FILES["file"]["size"] < 900000)) { $image = str_replace(' ', '_', $_FILES['file']['name']); if ($_FILES["file"]["error"] > 0) { $error[] = "*Return Code: " . $_FILES["file"]["error"] . "<br />"; } elseif (file_exists($filepath . $image)) { $error[] = '*Image exists: ' . $image ; } else { $uploadedfile = $_FILES["file"]["tmp_name"]; $size = getimagesize($uploadedfile); $type = $size['mime']; $width = $size[0]; $height = $size[1]; $filename = $filepath.$image; if($height > $setHeight || $width > $setWidth) { $newwidth=$setWidth; $newheight=($height/$width)*$setWidth; $tmp=imagecreatetruecolor($newwidth,$newheight); if($size[2] == IMAGETYPE_GIF) { $src = imagecreatefromgif($uploadedfile); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); imagegif($tmp,$filename,100); } elseif($size[2] == IMAGETYPE_JPEG) { $src = imagecreatefromjpeg($uploadedfile); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); imagejpeg($tmp,$filename,100); } elseif($size[2] == IMAGETYPE_PNG) { $src = imagecreatefrompng($uploadedfile); imagecopyresampled($tmp,$src,0,0,0,0,$newwidth,$newheight,$width,$height); imagepng($tmp,$filename,9); } imagedestroy($src); imagedestroy($tmp); return $image; } else { if(move_uploaded_file($uploadedfile, $filename)) { return $image; } $error[] = '*Failed during file movement!'; } } } else { $error[] = "*Invalid file"; } } return $error; } //call function: //using defaults $image = uploadImage(); //specify arguments $image = uploadImage(20,40,'images/upload'); if(!is_array($image)) { //do database insert; $image holds image name. } else { foreach($image as $error) { echo $error . '<br />'; } } Quote Link to comment https://forums.phpfreaks.com/topic/230302-keep-receiving-a-failed-to-open-stream-for-image-error/#findComment-1186035 Share on other sites More sharing options...
Pikachu2000 Posted March 11, 2011 Share Posted March 11, 2011 Does the 'upload' directory exist withing the same directory as that script, and does php have permission to write to it? Quote Link to comment https://forums.phpfreaks.com/topic/230302-keep-receiving-a-failed-to-open-stream-for-image-error/#findComment-1186036 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.