welshbryant Posted March 17, 2007 Share Posted March 17, 2007 Hey fellow PHPers, I am currently trying to upload an image to my mysql file server. It seems to go through however the file is never actually saved on the server. Attached is my code and hopefully someone can catch my mistake. <form name="form1" method = "post" enctype = "multipart/form-data"> Photographer name: <input type="text" name="authorname" size="40" /> <br /> Upload File: <input type="file" name="filename" id = "filename" size="40" /> <br /> File Type: <select name = "select"> <option value = "JPEG">JPEG</option> <option value = "GIF">GIF</option> <option value = "PNG">PNG</option> <option value = "other">Other</option> </select> <br /> Photo Name: <input type = "text" name = "photoname" /> <br /> Photo Description: <input type = "text" name = "photodescription" /> <br /> <input type="submit" value = "submit" /> <input type="reset" value = "reset"/> </form> <?php include("connect.php") ; $path = "/images/" ; $authname = $_POST['authorname']; $phototype = $_POST['select']; $photoitself = $_POST['filename']; $photoname = $_POST['photoname']; $photodesc = $_POST['photodescription']; move_uploaded_file($files['filename'] ['tmp_name'],"/public_html/images/" . $_FILES['filename']['name']); echo "stored in: " . "images/" . $_FILES['filename']['name']; ?> the addphoto3.php is stored under the public_html folder of my web server, and there is an images folder within the public_html where i want the images to be stored. Any help is appreciated. Quote Link to comment https://forums.phpfreaks.com/topic/43082-uploading-an-image-to-a-file-server/ Share on other sites More sharing options...
The Bat Posted March 17, 2007 Share Posted March 17, 2007 You should change this line: move_uploaded_file($files['filename']['tmp_name'],"/public_html/images/" . $_FILES['filename']['name']); to: move_uploaded_file($_FILES['filename']['tmp_name'],"/public_html/images/" . $_FILES['filename']['name']); If that doesn't help, you could change the above to: if (move_uploaded_file($_FILES['filename']['tmp_name'],"/public_html/images/" . $_FILES['filename']['name'])) { echo 'Image uploaded!'; } else { echo 'Error: '.$_FILES['filename']['error']; } And then look up the error code here: http://us3.php.net/manual/en/features.file-upload.errors.php Also, is addphoto3.php the PHP code you posted? If so, then you should remove '/public_html/' from the above line. Quote Link to comment https://forums.phpfreaks.com/topic/43082-uploading-an-image-to-a-file-server/#findComment-209297 Share on other sites More sharing options...
welshbryant Posted March 17, 2007 Author Share Posted March 17, 2007 hey the bat, these are the error messages i receive: Warning: move_uploaded_file(/public_html/images/doggy.jpg): failed to open stream: No such file or directory in /home/welsh/public_html/addphoto3.php on line 55 Warning: move_uploaded_file(): Unable to move '/tmp/phpn64U28' to '/public_html/images/doggy.jpg' in /home/welsh/public_html/addphoto3.php on line 55 Error: 0 for the code: include("connect.php") ; $path = "/images/" ; $authname = $_POST['authorname']; $phototype = $_POST['select']; $photoitself = $_POST['filename']; $photoname = $_POST['photoname']; $photodesc = $_POST['photodescription']; if (move_uploaded_file($_FILES['filename']['tmp_name'],"/public_html/images/" . $_FILES['filename']['name'])) { echo 'Image uploaded!'; } else { echo 'Error: '.$_FILES['filename']['error']; } does this have something to do with the fopen/fread commands? and if it does what would you suggest using. Since the code above is addphoto3, it is in the public_html folder hence i removed that part from where it will be saved to just images/. Quote Link to comment https://forums.phpfreaks.com/topic/43082-uploading-an-image-to-a-file-server/#findComment-209592 Share on other sites More sharing options...
welshbryant Posted March 17, 2007 Author Share Posted March 17, 2007 hey the bat, the last post was made in error (i had forgot to delete the public_html from the code). It says image uploaded however it uploads the php file (addphoto3 to the images folder) and not the image itself. Any idea on how to get the image itself in the folder? Quote Link to comment https://forums.phpfreaks.com/topic/43082-uploading-an-image-to-a-file-server/#findComment-209598 Share on other sites More sharing options...
welshbryant Posted March 18, 2007 Author Share Posted March 18, 2007 bump for help Quote Link to comment https://forums.phpfreaks.com/topic/43082-uploading-an-image-to-a-file-server/#findComment-209738 Share on other sites More sharing options...
The Bat Posted March 18, 2007 Share Posted March 18, 2007 Hmm, I copied your code and modified it to work on my webserver. First, I gave the submit button a name, and then added an if statement around move_uploaded_file so that it only tries to upload when the submit button is clicked. Also, did you chmod your images folder to 777? Here is the new code: <form action="upload.php" method = "post" enctype = "multipart/form-data"> Photographer name: <input type="text" name="authorname" size="40" /> Upload File: <input type="file" name="filename" id = "filename" size="40" /> File Type: <select name = "select"> <option value = "JPEG">JPEG</option> <option value = "GIF">GIF</option> <option value = "PNG">PNG</option> <option value = "other">Other</option> </select> Photo Name: <input type = "text" name = "photoname" /> Photo Description: <input type = "text" name = "photodescription" /> <input name="submit" type="submit" value = "submit"/> <input type="reset" value = "reset"/> </form> <?php include("connect.php"); $path = "/images/"; $authname = $_POST['authorname']; $phototype = $_POST['select']; $photoitself = $_POST['filename']; $photoname = $_POST['photoname']; $photodesc = $_POST['photodescription']; if ($_POST['submit']) { if (move_uploaded_file($_FILES['filename']['tmp_name'], $path.$_FILES['filename']['name'])) { echo 'Image uploaded!'; } else { echo 'Sorry, your image wasn\'t uploaded. Upload error: '.$_FILES['filename']['error']; } } ?> That should do it for you. Good luck! Quote Link to comment https://forums.phpfreaks.com/topic/43082-uploading-an-image-to-a-file-server/#findComment-209807 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.