dfowler Posted April 5, 2008 Share Posted April 5, 2008 Hey guys, I know it been addressed on here hundreds of times. However, each time it's been done a different way. I'm hoping to upload pdf's to a folder on a server. Then store the location into a database for easy reference later on. This seems to be the favorite among everybody on how to upload files correctly. I was hoping somebody could point me to a good tutorial on how to perform this action. Thanks for any information. Link to comment https://forums.phpfreaks.com/topic/99766-upload-pdf/ Share on other sites More sharing options...
quiettech Posted April 5, 2008 Share Posted April 5, 2008 Check Chapter 39 of the PHP Manual. The global $_FILES holds the data you need to insert into the database. Link to comment https://forums.phpfreaks.com/topic/99766-upload-pdf/#findComment-510252 Share on other sites More sharing options...
dfowler Posted April 7, 2008 Author Share Posted April 7, 2008 Ok here is where I am right now. I found a basic tutorial for uploading to a server. Here is the code: index.php <form enctype="multipart/form-data" action="uploader.php" method="POST"> <input type="hidden" name="MAX_FILE_SIZE" value="100000" /> Choose a file to upload: <input name="uploadedfile" type="file" /><br /> <input type="submit" value="Upload File" /> </form> uploader.php <?php $target_path = "pdfs/"; $target_path = $target_path . basename($_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded"; } else { echo "There was an error uploading the file, please try again!"; } ?> Now I need to save the file name and path into the database for reference. I am assuming I can insert $target_path? As I said, this is all completely new to me so any help would be great. Link to comment https://forums.phpfreaks.com/topic/99766-upload-pdf/#findComment-511153 Share on other sites More sharing options...
moon 111 Posted April 7, 2008 Share Posted April 7, 2008 Yes, add $target_path to the database. Link to comment https://forums.phpfreaks.com/topic/99766-upload-pdf/#findComment-511157 Share on other sites More sharing options...
dfowler Posted April 7, 2008 Author Share Posted April 7, 2008 Hey guys, here is where I am now. The code looks like it should work, however, I keep getting the error message and nothing is uploaded. Is there some setting I need to adjust on the server for this to work? Here is the code now: <?php include 'system.php'; $date = date("Y-m-d"); $path = "pdfs/"; $target_path = $path . basename($_FILES['uploadedfile']['name']); if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { echo "The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded"; $sql = "INSERT INTO pdfs (name, location, date) VALUES ('". $_FILES['uploadedfile']['name'] ."', '". $target_path ."', '". $date ."')"; mysql_query($sql) or die (mysql_error()); } else { echo "There was an error uploading the file (". basename($_FILES['uploadedfile']['name']). "), please try again!"; } ?> Link to comment https://forums.phpfreaks.com/topic/99766-upload-pdf/#findComment-511302 Share on other sites More sharing options...
dfowler Posted April 7, 2008 Author Share Posted April 7, 2008 I tested the script on a separate server and it works perfectly. Does anybody know what settings need to be adjusted to allow file uploads this way? Link to comment https://forums.phpfreaks.com/topic/99766-upload-pdf/#findComment-511328 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.