oceans Posted April 30, 2007 Share Posted April 30, 2007 Dear People, Can you please help me in uploading files from client browse and storing in a specific folder? I got this code, but it is not working. I believe it could be the placement. “ <form action="examplefileupload.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> <?php if (($_FILES["file"]["type"] == "image/gif") || ($_FILES["file"]["type"] == "image/pjpeg") && ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "Invalid file"; } ?> </form> “ Quote Link to comment Share on other sites More sharing options...
oceans Posted April 30, 2007 Author Share Posted April 30, 2007 Dear People, I redo my code, but no luck, I know it should work, but I think somthing is missing, please help " <form action="examplefileupload.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /> <br /> <input type="submit" name="submit" value="Submit" /> <?php if (($_FILES["file"]["type"] == "image/gif")|| ($_FILES["file"]["type"] == "image/jpg")&& ($_FILES["file"]["size"] < 20000)) { if ($_FILES["file"]["error"] > 0) { echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; } else { echo "Upload: " . $_FILES["file"]["name"] . "<br />"; echo "Type: " . $_FILES["file"]["type"] . "<br />"; echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />"; echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />"; if (file_exists("upload/" . $_FILES["file"]["name"])) { echo $_FILES["file"]["name"] . " already exists. "; } else { move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]); echo "Stored in: " . "upload/" . $_FILES["file"]["name"]; } } } else { echo "ONLY Gif or JPG Files!"; } ?> " Quote Link to comment Share on other sites More sharing options...
oceans Posted April 30, 2007 Author Share Posted April 30, 2007 Can any one pleae help me, I am getting no where. :'( Quote Link to comment Share on other sites More sharing options...
john010117 Posted April 30, 2007 Share Posted April 30, 2007 What exactly is "missing"? And for everyone's sake, put [ code ][ /code ] tags around your code (without the spaces). Quote Link to comment Share on other sites More sharing options...
oceans Posted April 30, 2007 Author Share Posted April 30, 2007 Dear John, Thanks for reply, the whole thing will go into body. I do not know what is missing, I can't upoad *.jpg file, but my code seems OK, it is not working since the first time. Quote Link to comment Share on other sites More sharing options...
oceans Posted April 30, 2007 Author Share Posted April 30, 2007 Any Kind hearts! Quote Link to comment Share on other sites More sharing options...
oceans Posted April 30, 2007 Author Share Posted April 30, 2007 Please help me, Quote Link to comment Share on other sites More sharing options...
oceans Posted May 2, 2007 Author Share Posted May 2, 2007 Dear Frineds, I am not moving ahead, please help me. Quote Link to comment Share on other sites More sharing options...
snowdog Posted May 2, 2007 Share Posted May 2, 2007 Let's look at an obvious setting situation. Have you checked your php settings to allow an upload to the directory you are trying to upload to? I had my code right and it took me a day and a half to figure out the directory was not set up to allow uploads. Snowdog Quote Link to comment Share on other sites More sharing options...
oceans Posted May 2, 2007 Author Share Posted May 2, 2007 Dear SnowDog, Thanks I never know I have to enable it, but I found out that it has been enabled by default, got I got to do anymore settings. Quote Link to comment Share on other sites More sharing options...
john010117 Posted May 2, 2007 Share Posted May 2, 2007 1) Set the directory (to which the files will upload to) permissions to 777. 2) Replace your form to this: <form action="examplefileupload.php" method="post" enctype="multipart/form-data"> <label for="file">Filename:</label> <input type="file" name="file" id="file" /><br /> <input type="submit" name="submit" value="Submit" /> </form> (you didn't put the end tag for the form). See if that helps. Quote Link to comment Share on other sites More sharing options...
snowdog Posted May 2, 2007 Share Posted May 2, 2007 Here is my upload code. This is the html form to choose your upload. In the first part I am passing variable some variables through so it knows what table and file I am uploading it and it changes the name of the file. Maybe this can help you. I pieced code together to come up with what worked for me. Hope this helps. Snowdog <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>Untitled</title> </head> <body> <? $id = $_REQUEST['id']; $filename = $_REQUEST['filename'].".mp3"; echo " <form enctype='multipart/form-data' method=\"post\" action=\"edit_reminder_upload_file.php\">\n"; echo " Upload file and rename it to $filename\n"; echo " <table width=\"90%\" align=\"center\">\n"; echo " <tr>\n"; echo " <td width=\"150\" style=\"font-family: verdana; font-size: 12;\">New File:</td>\n"; echo " <td style=\"font-family: verdana; font-size: 12;\"><input type=\"hidden\" name=\"MAX_FILE_SIZE\" value=\"500000000\" /><input type=\"file\" name=\"thumb\" value=\"\"></td>\n"; echo " </tr>\n"; echo " </table>"; echo " <input type=\"hidden\" name=\"filename\" value=\"$filename\">\n"; echo " <input type=\"hidden\" name=\"id\" value=\"$id\">\n"; echo " <input type=\"submit\" name=\"submit\" value=\"submit changes\">\n"; echo " </form>"; ?> </body> </html> and here is the 2nd part of upload where it does the work. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"> <html> <head> <title>Untitled</title> </head> <body> <? $filename = $_REQUEST['filename']; $id = $_REQUEST['id']; if(move_uploaded_file($_FILES['thumb']['tmp_name'], "mp3/coaching_call/".$filename)) { echo "Upload Success"; include("include/config.php"); $query = "UPDATE call_reminder SET completed='1' WHERE id='$id'"; mysql_query($query) or die('Query failed: ' . mysql_error()); } else { echo "Upload Failed"; } ?> </body> </html> Quote Link to comment Share on other sites More sharing options...
oceans Posted May 2, 2007 Author Share Posted May 2, 2007 Thanks friends, I manged to get my code working but with the following error, can you please help me understand the error " Warning: move_uploaded_file(upload/image.GIF) [function.move-uploaded-file]: failed to open stream: No such file or directory in C:\wamp\www\MyPHP\examplefileupload.php on line 71 Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move 'c:/wamp/tmp\php3F.tmp' to 'upload/image.GIF' in C:\wamp\www\MyPHP\examplefileupload.php on line 71 Stored in: upload/image.GIF " Line 71 is "move_uploaded_file($_FILES["file"]["tmp_name"],"upload/" . $_FILES["file"]["name"]);" SnowDog, I have not tried your code yet. Quote Link to comment Share on other sites More sharing options...
oceans Posted May 2, 2007 Author Share Posted May 2, 2007 People, I solved it, I did not have the folder in the first place, thats why. One more thing in my file criteria, *.gif is ok but *.jpg is not. can you help me. 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.