/    Sign up×
Community /Pin to ProfileBookmark

How to upload pdf files

Hello to all,

Im looking to upload pdf files to a server, just not sure how to do it. Im assuming it works similar to uploading images. I have successfully built an image uploader. Could someone show me how to modify it for pdf files?

Heres my code

[code]
<form enctype=”multipart/form-data” action=”addblogphoto.php” method=”POST”>
<td><input type=”file” name=”photo” /></td>
</tr>
<tr>
<td><input type=”submit” value=”Upload” /></td>
</tr>
</form>
[/code]

And the script

[code]
<?php
error_reporting (E_ALL ^ E_NOTICE);
//This is the directory where songs will be saved

$target = “”;
$target = $target . basename( $_FILES[‘photo’][‘name’]);

//This gets all the other information from the form
$photo=($_FILES[‘photo’][‘name’]);

// Connects to your Database
mysql_connect(“localhost”, “root”) or die(mysql_error()) ;
mysql_select_db(“test_blog”) or die(mysql_error()) ;

//Writes the information to the database
mysql_query(“INSERT INTO `photo`(blogphoto) VALUES (‘$photo’)”);

//Writes the image to the server
if(move_uploaded_file($_FILES[‘photo’][‘tmp_name’], $target))
{

//Tells you if its all ok
echo “The file “. basename( $_FILES[‘uploadedfile’][‘name’]). ” has been uploaded, and your information has been added to the directory”;
header(“location: index.php”);
}
else {

//Gives and error if its not
echo “Sorry, there was a problem uploading your file.”;
}
?>
[/code]

ANy help would be greatly appreciated!

to post a comment
PHP

2 Comments(s)

Copy linkTweet thisAlerts:
@qjensenOct 18.2010 — Your script should work just fine with any file type. Have you tried uploading a pdf with your existing script?
Copy linkTweet thisAlerts:
@jimmygauthorOct 18.2010 — Your script should work just fine with any file type. Have you tried uploading a pdf with your existing script?[/QUOTE]

I did, but with further testing (used smaller file sizes) it seems to work. Sorry I never thought to check the file sizes. Is there a way to limit this script to only pdf file types?
×

Success!

Help @jimmyg spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.8,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...