ngreenwood6 Posted August 19, 2008 Share Posted August 19, 2008 I am having a problem trying to upload a file and then display it on another page. I am getting this error: Warning: move_uploaded_file(c:/wamp/www/upload/upload/) [function.move-uploaded-file]: failed to open stream: Permission denied in C:\wamp\www\upload\check_image.php on line 27 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\wamp\tmp\php609.tmp' to 'c:/wamp/www/upload/upload/' in C:\wamp\www\upload\check_image.php on line 27 I am trying to upload the upload the file to "c:\wamp\www\upload\upload\". I am using wamp server obviously so if you wer to use the url it would be "http://localhost/upload/upload/". My upload file looks like this: upload.php <?php //database variables $host = "localhost"; $user = "root"; $pass = ""; $db = "pictures"; $table = "data"; //connect to the database $connect = mysql_connect($host, $user, $pass); //select database mysql_select_db($db); //get variables from form $image_caption = $_POST['image_caption']; $image_username = $_POST['image_username']; $image_tempname = $_POST['image_filename']['name']; $today = date("Y-m-d"); //upload image and make sure path is correct $imagedir = "c:/wamp/www/upload/upload/"; $imagename = $imagedir . $image_tempname; if (move_uploaded_file($_FILES['image_filename']['tmp_name'], $imagename)) { //get info about the image being uploaded list($width, $height, $type, $attr) = getimagesize($imagename); switch ($type) { case 1: $ext = ".gif"; break; case 2: $ext = ".jpg"; break; case 3: $ext = ".png"; break; default: echo "Sorry, but the file you uploaded was not a GIF, JPG, or " . "PNG file."; echo "Please hit your browser's 'back' button and try again."; } //insert info into image table $insert = "INSERT INTO insert (image_caption, image_username, image_date) VALUES ('$image_caption','$image_username','$today')"; $insertresults = mysql_query($insert) or die(mysql_error()); $lastpicid = mysql_insert_id(); $newfilename = $imagedir . $lastpicid . $ext; rename($imagename, $newfilename); } ?> <html> <head> <title>Here is your pic!</title> </head> <body> <h1>So how does it feel to be famous?</h1> <br /> <br /> <p>Here is the picture that you just uploaded to our servers:</p> <img src="upload/<?php echo $lastpicid . $ext; ?>" align="left" /> <strong><?php echo $image_name; ?></strong> <br /> This image is a <?php echo $ext; ?> image.<br /> It is <?php echo $width ?> pixels wide and <?php echo $height; ?> pixels high.<br /> It was uploaded on <?php echo $today; ?>. </body> </html> Any help is greatly appreciated. If you have any questions feel free to ask. Link to comment https://forums.phpfreaks.com/topic/120403-solved-move-uploaded-file-help/ Share on other sites More sharing options...
genericnumber1 Posted August 19, 2008 Share Posted August 19, 2008 - check the file permissions and make sure you have read/write permissions for it. - make sure your form is multipart/form-data encoded. - check your safe_mode setting in your php.ini file or phpinfo() display, if it's on, try disabling it. Link to comment https://forums.phpfreaks.com/topic/120403-solved-move-uploaded-file-help/#findComment-620361 Share on other sites More sharing options...
ngreenwood6 Posted August 19, 2008 Author Share Posted August 19, 2008 I am on my local computer(wamp) so of course I have permissions to it, the form is multiplart/form-data, and safe_mode setting is off. Any other suggestions? Link to comment https://forums.phpfreaks.com/topic/120403-solved-move-uploaded-file-help/#findComment-620378 Share on other sites More sharing options...
genericnumber1 Posted August 19, 2008 Share Posted August 19, 2008 have you created the directories in question.. in this instance, c:/wamp/www/upload/upload/. Sometimes people will expect php to create these directories for them, that's the only reason I ask. Link to comment https://forums.phpfreaks.com/topic/120403-solved-move-uploaded-file-help/#findComment-620400 Share on other sites More sharing options...
ngreenwood6 Posted August 19, 2008 Author Share Posted August 19, 2008 yes, there is a directory named c:/wamp/www/upload/ which is where the main files are (ex. index.php) and there is a directory called c:/wamp/www/upload/upload/ that is where the files are supposed to be saved to. Link to comment https://forums.phpfreaks.com/topic/120403-solved-move-uploaded-file-help/#findComment-620435 Share on other sites More sharing options...
ngreenwood6 Posted August 19, 2008 Author Share Posted August 19, 2008 I know that someone has to have run into this problem before. If anyone has any suggestions please let me know. Thanks Link to comment https://forums.phpfreaks.com/topic/120403-solved-move-uploaded-file-help/#findComment-620499 Share on other sites More sharing options...
genericnumber1 Posted August 19, 2008 Share Posted August 19, 2008 for funsies try adding these lines above the move_uploaded_file line <?php chmod($_FILES['image_filename']['tmp_name'], 0777); chmod($imagedir, 0777); ?> I should note that chmod isn't supposed to work on windows, but I've heard reports of it working under some circumstances. Link to comment https://forums.phpfreaks.com/topic/120403-solved-move-uploaded-file-help/#findComment-620531 Share on other sites More sharing options...
ngreenwood6 Posted August 20, 2008 Author Share Posted August 20, 2008 just in case anyone cares I figured out the issue i changed this code: $image_tempname = $_POST['image_filename']['name']; to this code: $image_tempname = $_FILES['image_filename']['name']; So I accidently put post where the files command should have been. Thought this might be helpful for some of you out there. I would have thought that someone would have caught this though. oh well. Link to comment https://forums.phpfreaks.com/topic/120403-solved-move-uploaded-file-help/#findComment-620745 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.