Created
May 21, 2013 16:31
-
-
Save rajvanshipradeep15/5621196 to your computer and use it in GitHub Desktop.
php: file upload
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 | |
$uploadpath = $_SERVER['DOCUMENT_ROOT']."/useruploads"; | |
$allowedExts = array("gif", "jpeg", "jpg", "png"); | |
$extension = end(explode(".", $_FILES["upload"]["name"])); | |
if ((($_FILES["upload"]["type"] == "image/gif") | |
|| ($_FILES["upload"]["type"] == "image/jpeg") | |
|| ($_FILES["upload"]["type"] == "image/jpg") | |
|| ($_FILES["upload"]["type"] == "image/pjpeg") | |
|| ($_FILES["upload"]["type"] == "image/x-png") | |
|| ($_FILES["upload"]["type"] == "image/png")) | |
&& ($_FILES["upload"]["size"] < 20000) | |
&& in_array($extension, $allowedExts)) | |
{ | |
if ($_FILES["upload"]["error"] > 0) | |
{ | |
echo "Return Code: " . $_FILES["upload"]["error"] . "<br>"; | |
} | |
else | |
{ | |
echo "Upload: " . $_FILES["upload"]["name"] . "<br>"; | |
echo "Type: " . $_FILES["upload"]["type"] . "<br>"; | |
echo "Size: " . ($_FILES["upload"]["size"] / 1024) . " kB<br>"; | |
echo "Temp file: " . $_FILES["upload"]["tmp_name"] . "<br>"; | |
if (file_exists("upload/" . $_FILES["upload"]["name"])) | |
{ | |
echo $_FILES["upload"]["name"] . " already exists. "; | |
} | |
else | |
{ | |
$imgUploadPath = $uploadpath."/".$_FILES["upload"]["name"]; | |
echo "path : ".$imgUploadPath; | |
move_uploaded_file($_FILES["upload"]["tmp_name"], | |
$imgUploadPath); | |
echo "Stored in: " . "uploads/" . $_FILES["upload"]["name"]; | |
} | |
} | |
} | |
else | |
{ | |
echo "Invalid file"; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment