june_c21 Posted March 14, 2008 Share Posted March 14, 2008 hi, i am doing a page where user need add their material into c:\PI. I try to run this system. It didn't not show any error but it fail to upload the file to c:\PI. Anything wrong? Can someone show me the error? thanks <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" /> <title>Drawing Database</title> <style type="text/css"> <!-- body { background-color: #0066FF; } .style6 {font-family: "Arial Black"; font-size: 12px; } --> </style></head> <body> <p> </p> <p> </p> <p> </p> <form action="add.php" method="post" enctype="multipart/form-data" name="form1" id="form1"> <p align="center" class="style6">Add</p> <table width="194" border="1" align="center"> <tr> <td width="157"><span class="style6">GF</span></td> <td width="11"><span class="style6">:</span></td> <td width="8"><label> <select name="gf" id="gf"> <option value="gf1">GF1</option> <option value="gf2">GF2</option> <option value="gf3">GF3</option> <option value="gf4">GF4</option> <option value="miscellaneous">Miscellaneous</option> </select> </label></td> </tr> <tr> <td><span class="style6">Drawing No </span></td> <td><span class="style6">:</span></td> <td><label> <input name="drawing_no" type="text" id="drawing_no" /> </label></td> </tr> <tr> <td><span class="style6">Manufacture No </span></td> <td><span class="style6">:</span></td> <td><label> <input name="manufac_no" type="text" id="manufac_no" /> </label></td> </tr> <tr> <td><span class="style6">Title</span></td> <td><span class="style6">:</span></td> <td><label> <textarea name="title" id="title"></textarea> </label></td> </tr> <tr> <td class="style6">Upload </td> <td class="style6">:</td> <td><label> <input type="file" name="file" /> </label></td> </tr> <tr> <td> </td> <td> </td> <td><label> <input type="submit" name="Submit" value="Submit" /> </label></td> </tr> </table> <p> <label></label> </p> </form> <p> </p> </body> </html> php code if ($HTTP_POST_VARS['submit']) { if (!is_uploaded_file($HTTP_POST_FILES['file']['tmp_name'])) { $error = "You did not upload a file!"; unlink($HTTP_POST_FILES['file']['tmp_name']); // assign error message, remove uploaded file, redisplay form. } else { //A file was uploaded $maxfilesize=300000; if ($HTTP_POST_FILES['file']['size'] > $maxfilesize) { $error = "File is too large."; unlink($HTTP_POST_FILES['file']['tmp_name']); // assign error message, remove uploaded file, redisplay form. } else { //File has passed all validation, copy it to the final destination and remove the temporary file: copy($HTTP_POST_FILES['file']['tmp_name'],$HTTP_POST_FILES['file']['name']); unlink($HTTP_POST_FILES['file']['tmp_name']); print "File has been successfully uploaded!"; exit; } } } $gf = $_POST['gf']; $drawing_no = $_POST['drawing_no']; $manufac_no = $_POST['manufac_no']; $title = $_POST['title']; $query= "INSERT INTO drawings( gf,drawing_no,manufac_no,title) VALUES ('$gf', '$drawing_no','$manufac_no','$title') "; $result = mysql_query($query,$dblink); Quote Link to comment Share on other sites More sharing options...
AdRock Posted March 14, 2008 Share Posted March 14, 2008 it appears you are not specifying where to copy the image to in this line copy($HTTP_POST_FILES['file']['tmp_name'],$HTTP_POST_FILES['file']['name']); This is my code $idir = "../images/gallery/full/"; // Path To Images Directory $_FILES['imagefile']['name']; // Set $url To Equal The Filename For Later Use if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") { $file_ext = strrchr($_FILES['imagefile']['name'], '.'); // Get The File Extention In The Format Of , For Instance, .jpg, .gif or .php $copy = copy($_FILES['imagefile']['tmp_name'], "$idir" . $_FILES['imagefile']['name']); // Move Image From Temporary Location To Permanent Location if ($copy) { // If The Script Was Able To Copy The Image To It's Permanent Location print 'Image uploaded successfully.<br />'; // Was Able To Successfully Upload Image Quote Link to comment Share on other sites More sharing options...
june_c21 Posted March 14, 2008 Author Share Posted March 14, 2008 copy($HTTP_POST_FILES['file']['tmp_name'],$HTTP_POST_FILES['file']['name']); i put it in this way copy($HTTP_POST_FILES['file']['tmp_name'],$HTTP_POST_FILES['file']['c:/PI']); but it stil doesn't work. Why ? AdRock, I a bit blur with your code. Can guide me more? thanks Quote Link to comment Share on other sites More sharing options...
AdRock Posted March 14, 2008 Share Posted March 14, 2008 This may help you http://www.tizag.com/phpT/fileupload.php http://php.about.com/od/advancedphp/ss/php_file_upload_2.htm Quote Link to comment Share on other sites More sharing options...
june_c21 Posted March 14, 2008 Author Share Posted March 14, 2008 now i try using Adrock code but still fail $idir = "c:/PI" ; copy($HTTP_POST_FILES['file']['tmp_name'],"$dir". $HTTP_POST_FILES['file']['name']); anyone can help me solve this? thanks in advance Quote Link to comment Share on other sites More sharing options...
AdRock Posted March 14, 2008 Share Posted March 14, 2008 make sure they are both $idir or $dir You have one of each Quote Link to comment Share on other sites More sharing options...
derrick1123 Posted March 14, 2008 Share Posted March 14, 2008 http://www.w3schools.com/php/php_file_upload.asp ^they have a good tutorial...but I think AdRock got it for you. Quote Link to comment Share on other sites More sharing options...
june_c21 Posted March 14, 2008 Author Share Posted March 14, 2008 i change that to $idir but still fail. Quote Link to comment Share on other sites More sharing options...
AdRock Posted March 14, 2008 Share Posted March 14, 2008 i don't know if it will make any difference but out of curiositym, change $HTTP_POST_FILES to $_FILES Quote Link to comment Share on other sites More sharing options...
june_c21 Posted March 14, 2008 Author Share Posted March 14, 2008 i change it to $_Files but the file stil didnt appear in c:/PI Quote Link to comment Share on other sites More sharing options...
june_c21 Posted March 14, 2008 Author Share Posted March 14, 2008 i solved it. Thanks AdRock !!! but i got another question how to save the file name into the database? Quote Link to comment Share on other sites More sharing options...
AdRock Posted March 14, 2008 Share Posted March 14, 2008 Can you post your code again? Did you use my exampl eor try using your own? If you used mine any you want to uploads gifs change this if ($_FILES['imagefile']['type'] == "image/jpg" || $_FILES['imagefile']['type'] == "image/jpeg" || $_FILES['imagefile']['type'] == "image/pjpeg") { to if ($_FILES['imagefile']['type'] == "image/gif" { Quote Link to comment Share on other sites More sharing options...
june_c21 Posted March 14, 2008 Author Share Posted March 14, 2008 Adrock, How to save the file name into database? 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.