Hi everyone,
I have a PHP code where I can upload files with any extension, but I would like to upload only pdf files. Can anyone please help me with this code?

<?php
// Where the file is going to be placed 
$target_path = "download/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */ $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!"; }?>

    One of the distinguishing features of that a PDF file must have is that the first line is [font=monospace]%PDF-n.n[/font] with [font=monospace]n.n[/font] being some version number such as [font=monospace]1.5[/font].

    The second-to-last line is a byte length for the content (slightly less than the size of the entire file) and the last line is [font=monospace]%%EOF[/font].

    Whether that's enough to confirm that you're looking at a PDF file depends on how sure you want to be that an alleged PDF file is actually a PDF file.

    See also [man]finfo_file[/man].

      Hi Weedpacket and thanks for replying,
      I'm just a newbie on PHP and all I want is some help on how to load files with .pdf extensions and I also want only one file name to be uploaded, not any file name. For example: news.pdf
      If the file is not a .pdf file and it does not have that name "news.pdf", then the user will not be able to upload the file.
      Can you please help me on this?

        Write a Reply...