Jump to content

Upload PDF


dfowler

Recommended Posts

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

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

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.