Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- $ cat pv.html
- <!DOCTYPE html>
- <html>
- <body>
- <form action="upload.php" method="post" enctype="multipart/form-data">
- Select image to upload:
- <input type="file" name="fileToUpload" id="fileToUpload">
- <input type="submit" value="Upload Image" name="submit">
- </form>
- </body>
- </html>
- $ cat upload.php
- <?php
- $target_dir = "/var/www/uploads/";
- $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
- $uploadOk = 1;
- $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
- echo "The value of target directory is =" . $target_dir . "</br>";
- echo "The value of target file is =" . $target_file . "</br>";
- echo "The value of uploadOk is =" . $uploadOk . "</br>";
- echo "The value of imageFileType is =" . $imageFileType . "</br>";
- echo "Upload: " . $_FILES["fileToUpload"]["name"] . "<br />";
- echo "Type: " . $_FILES["fileToUpload"]["type"] . "<br />";
- echo "Size: " . ($_FILES["fileToUpload"]["size"] / 1024) . " Kb<br />";
- echo "Temp file: " . $_FILES["fileToUpload"]["tmp_name"] . "<br />";
- echo "Error :" . $_FILES["fileToUpload"]["error"] . "<br / >";
- if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
- echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.";
- } else {
- echo "Sorry, there was an error uploading your file.";
- }
- $finfo = finfo_open(FILEINFO_MIME_TYPE);
- echo "</br> The value of finfo is =" . $finfo . "</br>";
- echo finfo_file($finfo, $target_file );
- finfo_close($finfo);
- ?>
- Reference
- http://php.net/manual/en/features.file-upload.php
- To find out error codes.
- http://php.net/manual/en/features.file-upload.errors.php
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement