Ruth Posted April 1, 2008 Share Posted April 1, 2008 I'm trying to allow a user to upload images and I getting the following errors: Warning: move_uploaded_file(C:/projects/pratice/WWW/ch07/images/) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\projects\pratice\WWW\ch07\check_image.php on line 17 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'C:\xampp\tmp\phpD9.tmp' to 'C:/projects/pratice/WWW/ch07/images/' in C:\projects\pratice\WWW\ch07\check_image.php on line 17 According to everything I've read it has something to do with the path, but I'm unsure how to fix it. Before I post my code below I ask that you not assume, if you don't understand something please ask. <?php //connect to db require_once('dbconnection.php'); //pull var from form $image_caption = $_POST['image_caption']; $image_username = $_POST['image_username']; $image_tempname = $_POST['image_filename']; $today = date("Y-m-d"); //upload image and check for image type //path not working $imageDir = "C:/projects/pratice/WWW/ch07/images/"; $imageName = $imageDir . $image_tempname; //check to see if file is valid upload file (uploaded by post) 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 <br />"; echo "Please hit your browser's 'back' button and try again"; } //insert info into image table $insert = "INSERT INTO images (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 you just uploaded to our servers:</p> <img src = "images/<?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> Link to comment https://forums.phpfreaks.com/topic/99025-images/ Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 Suggestions anyone ??? Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506700 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 you have specified the wrong path most likely be sure its exact Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506709 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 lol I know that but I'm not sure what the right path is. I'm following along with a book that is kinda like follow me then try it yourself. The show the path as c:/program files/apache group/apache2/test/images. I tired to follow this path manually and could not find apache group, i tired the path anyway and get the same error. Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506712 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 The path posted in my code is the right path to my files and to the image folder. Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506714 Share on other sites More sharing options...
redarrow Posted April 1, 2008 Share Posted April 1, 2008 in htdocs create a folder called images put the images in the folder then use this script u made but make sure it also in htdocs <?php //connect to db require_once('dbconnection.php'); //pull var from form $image_caption = $_POST['image_caption']; $image_username = $_POST['image_username']; $image_tempname = $_POST['image_filename']; $today = date("Y-m-d"); //upload image and check for image type //path not working $imageDir = "images/"; $imageName = $imageDir . $image_tempname; //check to see if file is valid upload file (uploaded by post) 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 images (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> <p>Here is the picture you just uploaded to our servers:</p> <img src = "images/<?php echo $lastpicid . $ext;?>" align="left"> <strong><?php echo $image_name;?></strong> This image is a <?php echo $ext;?> image. It is <?php echo $width;?> pixels wide and <?php echo $height;?> pixels high. It was uploaded on <?php echo $today;?>. </body> </html> Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506719 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 There are no images right now stored in the image folder. The user is supposed to upload whatever to the image folder. I'll try to find this document and see whats in it though. Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506721 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 try <?php $uploaddir = ''; $uploadfile = $uploaddir . basename($_FILES['upfile']['name']); echo '<pre>'; if (move_uploaded_file($_FILES['upfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; } echo 'Here is some more debugging info:'; print_r($_FILES); print "</pre>"; ?> Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506722 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 This is what I get when I tired your suggestion Possible file upload attack! Here is some more debugging info:Array ( [image_filename] => Array ( [name] => jim_carrey.jpg [type] => image/jpeg [tmp_name] => C:\xampp\tmp\phpDB.tmp [error] => 0 => 7938 ) ) Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506725 Share on other sites More sharing options...
redarrow Posted April 1, 2008 Share Posted April 1, 2008 try this quickly in htdocs and a folder caled images...... <?php $uploaddir = 'images/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; } ?> <form enctype="multipart/form-data" action=" " method="POST"> <!-- MAX_FILE_SIZE must precede the file input field --> <input type="hidden" name="MAX_FILE_SIZE" value="30000" /> <!-- Name of input element determines name in $_FILES array --> Send this file: <input name="userfile" type="file" /> <input type="submit" value="Send File" /> </form> Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506727 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 I'm confused about the htdocs folder, what does it have to do with my problem? I have a form that is before the code I posted ealier. Here is the form <html> <head> <title>Upload your pic to our site!</title> </head> <body> <form name = "form1" method = "post" action = "check_image.php" enctype = "multipart/form-data"> <table border = "0" cellpadding = "5"> <tr> <td>Image Title or Caption<br /> <em>Example: You talkin' to me?</em></td> <td> <input name="image_caption" type="text" id="item_caption" size="55" maxlength="255"> </td> </tr> <tr> <td>Your Username</td> <td> <input name="image_username" type="text" id="image_username" size="15" maxlength="255"> </td> </tr> <tr> <td>Upload Image:</td> <td> <input name="image_filename" type="file" id="image_filename"> </td> </tr> </table> <br /> <em>Acceptable image formats include: GIF, JPG/JPEG, and PNG.</em> <p align="center"><input type="submit" name="Submit" value="Submit"> <input type="reset" name="Submit2" value="Clear Form"> </p> </form> </body> </html> Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506735 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 I tired this $uploaddir = 'images/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo "File is valid, and was successfully uploaded.\n"; } else { echo "Possible file upload attack!\n"; } Along with the error messages I get Possible file upload attack! Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506737 Share on other sites More sharing options...
redarrow Posted April 1, 2008 Share Posted April 1, 2008 You should be sitting php pages in a folder called htdocs when you create a folder lets say images to now access images it images/ /<<< meaning open image folder or go inside image folder........... Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506739 Share on other sites More sharing options...
redarrow Posted April 1, 2008 Share Posted April 1, 2008 sorry dont no xamp have u read xamp manual and were xamp store there files.... Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506740 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 Thats just it I don't use htdocs. I store all my projecs in C:/projects. I use MyEclipse which reads the files in the folder projects. I can run and debug through MyEclipse. I don't manually upload anything to a server and I don't use htdocs. Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506742 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 OK same function as before but with a different function try: <?php if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n"; echo "Displaying contents\n"; readfile($_FILES['userfile']['tmp_name']); } else { echo "Possible file upload attack: "; echo "filename '". $_FILES['userfile']['tmp_name'] . "'."; } ?> Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506745 Share on other sites More sharing options...
redarrow Posted April 1, 2008 Share Posted April 1, 2008 I think it a server program problam my self......... apache wouldnt do that sorry m8. Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506748 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 Come on guys don't tell you've given up that easily I've been all over the net and can't seem to find a solution Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506749 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 I've tired if (is_uploaded_file($_FILES['userfile']['tmp_name'])) { echo "File ". $_FILES['userfile']['name'] ." uploaded successfully.\n"; echo "Displaying contents\n"; readfile($_FILES['userfile']['tmp_name']); } else { echo "Possible file upload attack: "; echo "filename '". $_FILES['userfile']['tmp_name'] . "'."; } and get Possible file upload attack: filename ''. Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506751 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 I'm not sure what you mean by I think it a server program problam my self......... apache wouldnt do that sorry mate. apache is my server, I'm running everything locally. Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506752 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 remove the else then tell me what u get ??? Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506755 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 Parse error: syntax error, unexpected $end in C:\projects\pratice\WWW\ch07\check_image.php on line 79 Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506757 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 That line is </html> wtf mate Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506761 Share on other sites More sharing options...
darkfreaks Posted April 1, 2008 Share Posted April 1, 2008 can u poste the whole code please ??? Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506764 Share on other sites More sharing options...
Ruth Posted April 1, 2008 Author Share Posted April 1, 2008 The whole code is one page 1 Link to comment https://forums.phpfreaks.com/topic/99025-images/#findComment-506765 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.