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. Quote Link to comment 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. Quote Link to comment 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? Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment 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 Quote Link to comment 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. Quote Link to comment 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. 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.