Jump to content
Larry Ullman's Book Forums

Ch 11 'Handling File Uploads' How2Pdf


Recommended Posts

I would like to know what changes to the code i need to make in order to uipload pdf files?

I would think that the changes are to be made somewhere around here:

 

 

$allowed = array ('image/pjpeg', 'image/jpeg', 'image/JPG', 'image/X-PNG', 'image/PNG', 'image/png','image/x-png');
if (in_array($_FILES['upload'] ['type'], $allowed)) {
 
 

 

Link to comment
Share on other sites

If you want to be able to upload pdf files in addition to those other file types, you need only amend the $allowed array to include the value 'application/pdf'. If you want to upload only pdf files you might want to check the file extension in addition to the file type e.g.

if ($_FILES['upload']['type'] == 'pdf' && substr($_FILES['upload']['tmp_name'], -4)  == '.pdf'){
  • Upvote 1
Link to comment
Share on other sites

 Share

×
×
  • Create New...