sildona Posted October 26, 2012 Share Posted October 26, 2012 The following error messages 1. [function.move-uploaded-file]: failed to open stream: No such file or directory 2. Unable to move '/tmp/coded file name' to .... [directory] result from the following code. <?php //This is the directory where images will be saved $target = "images/"; $target = $target . basename( $_FILES['image']['name']); //This gets all the other information from the form $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $email=$_POST['email']; $image=($_FILES['image']['name']); // Connects to your Database include "connect.php"; //Writes the information to the database mysql_query ( "INSERT INTO `database`(`first_name`,`last_name`,`email`,`image`,) VALUES ('$first_name','$last_name','$email','$image',)" ); //Writes the photo to the server if(move_uploaded_file($_FILES['image']['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."; } ?> Any help would be GREATLY apprecaited!! Quote Link to comment https://forums.phpfreaks.com/topic/269945-why-functionmove-uploaded-file-failed-to-open-stream-no-such-file-or-directory/ Share on other sites More sharing options...
jazzman1 Posted October 26, 2012 Share Posted October 26, 2012 (edited) Your directory is images/, no images. basename( $_FILES['image']['name']) . EDIT: just delete this line - $target = $target . basename( $_FILES['image']['name']); Edited October 26, 2012 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/269945-why-functionmove-uploaded-file-failed-to-open-stream-no-such-file-or-directory/#findComment-1387978 Share on other sites More sharing options...
sildona Posted October 26, 2012 Author Share Posted October 26, 2012 (edited) I deleted the line, but I still received an error: failed to open stream: Is a directory in .... [site directory] What is "Is" as directory? I did a search for Is and for directory in case I had some typos. Not finding anything. Edited October 26, 2012 by sildona Quote Link to comment https://forums.phpfreaks.com/topic/269945-why-functionmove-uploaded-file-failed-to-open-stream-no-such-file-or-directory/#findComment-1387984 Share on other sites More sharing options...
jazzman1 Posted October 26, 2012 Share Posted October 26, 2012 (edited) ls is a Unix command. I don't see any errors in this script. What permissions do you have to the image directory? EDIT: Also, check whether your html form has enctype=multipart/form-data. Edited October 26, 2012 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/269945-why-functionmove-uploaded-file-failed-to-open-stream-no-such-file-or-directory/#findComment-1387985 Share on other sites More sharing options...
jazzman1 Posted October 26, 2012 Share Posted October 26, 2012 (edited) Try, <?php //This is the directory where images will be saved $target = "images"; //This gets all the other information from the form $first_name=$_POST['first_name']; $last_name=$_POST['last_name']; $email=$_POST['email']; $img_name=basename(($_FILES['image']['name'])); $tmp_name = $_FILES["image"]["tmp_name"]; // Connects to your Database include "connect.php"; //Writes the information to the database mysql_query ( "INSERT INTO `database`(`first_name`,`last_name`,`email`,`image`) VALUES ('$first_name','$last_name','$email','$img_name')" ); //Writes the photo to the server if(move_uploaded_file($tmp_name, $target.'/'.$img_name)) { //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."; } ?> EDIT: You also had two errors in your sql string (two extra commas) I removed them... Edited October 26, 2012 by jazzman1 Quote Link to comment https://forums.phpfreaks.com/topic/269945-why-functionmove-uploaded-file-failed-to-open-stream-no-such-file-or-directory/#findComment-1388004 Share on other sites More sharing options...
jcbones Posted October 26, 2012 Share Posted October 26, 2012 Make sure your inputs are set with isset, or if you don't want null values, then empty. Quote Link to comment https://forums.phpfreaks.com/topic/269945-why-functionmove-uploaded-file-failed-to-open-stream-no-such-file-or-directory/#findComment-1388022 Share on other sites More sharing options...
sildona Posted October 26, 2012 Author Share Posted October 26, 2012 Got it. It works! Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/269945-why-functionmove-uploaded-file-failed-to-open-stream-no-such-file-or-directory/#findComment-1388028 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.