0

pls i want how to upload and retrive only pdf files in php and mysql code or any links..

2
Contributors
2
Replies
8
Views
5 Years
Discussion Span
Last Post by ratanji
1
<?php
$targetPath = $_SERVER['DOCUMENT_ROOT'].'/upload/';

if (isset($_POST['submit'])){

$filename = basename( $_FILES['file']['name'], ".pdf");

if($_FILES['file']['type']=='application/pdf') {
        $filename = preg_replace("/[^A-Za-z0-9_-]/", "", $filename).".pdf";
        $thumb = basename($filename, ".pdf");
        $cpy=1;
        do {
            $targetFile =  str_replace('//','/',$targetPath) ."Copy".$cpy. $filename;
            $filename="Copy".$cpy. $_FILES['file']['name'];
            $cpy++;
        }while(is_file($targetFile));

            if(move_uploaded_file($_FILES['file']['tmp_name'], $targetPath.$filename)) {             
                    $pdfWithPath = $targetPath.$filename;
                    echo "File Uploaded Successfully";
            }
}
else {
    echo "Please Upload pdf File";  
}
}

?>

<form method="post" action="" enctype="multipart/form-data">
    <input type="file" name="file" />
    <input type="submit" name="submit" value="Upload" />
</form>

Check your $targetPath path is correct and give 777 permission for folder upload

Edited by Bachu

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.