Created
February 28, 2018 12:49
-
-
Save rintoug/4d16735a1765f45248c1b5e7f79a133b to your computer and use it in GitHub Desktop.
Uploading files in PHP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Here is our upload script resides | |
//Check whether the form really submits | |
if($_SERVER["REQUEST_METHOD"] == "POST"){ | |
if(!empty($_FILES['image']['name'])) { | |
$uploadDir = './uploads/'; | |
$uploadFilename = $uploadDir.basename($_FILES['image']['name']); | |
//Check extension | |
$ext = pathinfo($filename, PATHINFO_EXTENSION); | |
if(!in_array($ext,array('jpg','png'))) { | |
echo "Oops. Invalid file type"; | |
exit; | |
} | |
if (move_uploaded_file($_FILES['file']['tmp_name'], $uploadFile)) { | |
echo "File Uploaded successfully!"; | |
} | |
else { | |
echo "Oops!. something went wrong!"; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment