/    Sign up×
Community /Pin to ProfileBookmark

upload a PDF file into mysql

I have a form that uploads a PDF but I don’t think that it’s performing a file type check. How can I do this so that ONLY a pdf is uploaded and not a php script?

Here’s my code:

[code=php]if(isset($_POST[‘upload’]) && $_FILES[‘userfile’][‘size’] > 0)
{
$fileName = $_FILES[‘userfile’][‘name’];
$tmpName = $_FILES[‘userfile’][‘tmp_name’];
$fileSize = $_FILES[‘userfile’][‘size’];
$fileType = $_FILES[‘userfile’][‘type’];

$fp = fopen($tmpName, ‘r’);
$content = fread($fp, filesize($tmpName));
$content = addslashes($content);
fclose($fp);

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
}

include(‘mysql_connect.php’)
$query = “INSERT INTO pdf (name, size, type, content) “.
“VALUES (‘$fileName’, ‘$fileSize’, ‘$fileType’, ‘$content’)”;

mysql_query($query) or die(‘Error, query failed’);[/code]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@Alan_PauthorDec 02.2008 — Also, I have some programs that require I set the file of folder to 777 chmode, because the file or folder needs to be writeable by the program. I understand this is a no-no, so what should I set it to that it will be protected but will still work?
×

Success!

Help @Alan_P 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 6.17,
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: @nearjob,
tipped: article
amount: 1000 SATS,

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

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,
)...