<html>
<head>
<title>PHP Pdf file Upload script : Example</title>
</head>
<body>
<div style="padding: 20px; border: 1px solid #999">
<h2>Upload PDF File :</h2>
<form enctype="multipart/form-data"
action="<?php print $_SERVER['PHP_SELF']?>" method="post">
<p><input type="hidden" name="MAX_FILE_SIZE" value="200000" /> <input
type="file" name="pdfFile" /><br />
<br />
<input type="submit" value="upload!" /></p>
</form>
</div>
</body>
</html>
<?php
if ( isset( $_FILES['pdfFile'] ) ) {
if ($_FILES['pdfFile']['type'] == "application/pdf") {
$source_file = $_FILES['pdfFile']['tmp_name'];
$dest_file = "upload/".$_FILES['pdfFile']['name'];
if (file_exists($dest_file)) {
print "The file name already exists!!";
}
else {
move_uploaded_file( $source_file, $dest_file )
or die ("Error!!");
if($_FILES['pdfFile']['error'] == 0) {
print "Pdf file uploaded successfully!";
print "<b><u>Details : </u></b><br/>";
print "File Name : ".$_FILES['pdfFile']['name']."<br.>"."<br/>";
print "File Size : ".$_FILES['pdfFile']['size']." bytes"."<br/>";
print "File location : upload/".$_FILES['pdfFile']['name']."<br/>";
}
}
}
else {
if ( $_FILES['pdfFile']['type'] != "application/pdf") {
print "Error occured while uploading file : ".$_FILES['pdfFile']['name']."<br/>";
print "Invalid file extension, should be pdf !!"."<br/>";
print "Error Code : ".$_FILES['pdfFile']['error']."<br/>";
}
}
}
?>
Note: You may get error failed to open stream: Permission denied in /Applications/XAMPP/xamppfiles/htdocs/mysql-error-code/sample.php on line 32 if you do not have permission to write to the destination folder on server.
More Posts related to PHP,
- How to destroy PHP session()
- PHP Code for sending Emails
- 403 forbidden error for Image
- macOS - cannot calculate MAC address: Using fd 9 hv_vm_create HV_ERROR [PHP XAMPP]
- Upload Pdf file using PHP Script
- PHP header location function not called
- Copy file from one directory to other in Php
- PHP.ini: How to Remove URL Forward Slash Before Single or Double Quotes
- PHP Base64 encoding decoding a variable
- PHP Fatal error : Call to a member function bind_param() on a non-object
- PHP Script to Upload Images to Server
- Upload docx file using PHP script
- How to Pretty Print JSON in PHP
- PHP Warning: Cannot modify header information - headers already sent
- PHP drag and drop file upload tutorial using dropzone.js
- Failed to load resource: net::ERR_CACHE_MISS PHP
- PHP 301 Redirect Permanently
- Call PHP function on Button click using jquery ajax
- Installing vue.js in Laravel 8
- Save current timestamp in MySQL using PHP mysqi binding
- Delete file using PHP code : unlink()
More Posts:
- How to save All Files at once in Notepad++ - NotepadPlusPlus
- Hide Scrollbar from Android Views - Android
- Microsoft Sign-in Error Code: 50058 (Request Id, Correlation Id and Timestamp) - Microsoft
- Android : Connection with adb was interrupted 0 attempts have been made to reconnect - Android
- How to Compare Strings in Bash Script - Bash
- Fix: Spring Boot REST HTTP Status 415 - Unsupported Media Type Error - Java
- Access Windows share folder in Ubuntu Device in Network - Ubuntu
- Change Android Toast background color - Android