<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,
- Upload Pdf file using PHP Script
- 403 forbidden error for Image
- Installing vue.js in Laravel 8
- Copy file from one directory to other in Php
- Remove URL Forward Slash Before Single or Double quotes in php.ini
- PHP Script to Upload Images to Server
- PHP Base64 encoding decoding a variable
- Upload docx file using PHP script
- Delete file using PHP code : unlink()
- PHP 301 Redirect Permanently
- PHP Fatal error : Call to a member function bind_param() on a non-object
- Call PHP function on Button click using jquery ajax
- PHP header location function not called
- Failed to load resource: net::ERR_CACHE_MISS PHP
- PHP Code for sending Emails
- How to destroy PHP session()
- PHP drag and drop file upload tutorial using dropzone.js
- PHP Warning: Cannot modify header information - headers already sent
More Posts:
- How to display Toast in a thread : Android - Android
- Change CKEditor Table Properties default width - CKEditor
- Mac OS X Stuck During Booting Gray Screen Logo and Spinner - Mac-OS-X
- Find Difference of two numbers - C-Program
- Share Multiple Images in WhatsApp using Android Intent - WhatsApp
- Instant Run requires Tools | Android | Enable ADB integration to be enabled - Android-Studio
- Setting up Cloud feature with Notepad++ - NotepadPlusPlus
- W3 : character data is not allowed here html validation error - Html
- List of 60 useful FTP Client Commands to access server - FTP
- Write javaScript code in Swedish using FikaScript - JavaScript
- Android Installation error: INSTALL_FAILED_OLDER_SDK on Device - Android
- Programmatically Send an Email from Android App using Intent - Android
- jQuery : Move to top of the page - jQuery
- PHP Code for sending Emails - PHP
- Error:The SDK Build Tools revision (XX.X.X) is too low for project. Minimum required is XX.X.X - Android