1

I need that code to upload only picture file and when you upload file extension like .pdf the code to be reject that file

if((isset($_FILES['file'])) && ($_FILES['file']['name']!='"')) { echo 'isset'.$_FILES['file']['name'];
$folder = 'upload/';
$file = basename($_FILES['file']['name']);
$size_maxi = 2000000;
$size = filesize($_FILES['file']['tmp_name']);
$extensions = array('.png', '.gif', '.jpg', '.jpeg');
$extension = strrchr($_FILES['file']['name'], '.');
//Start the file type verification
//If the extension is not in table 
if(!in_array($extension, $extensions)){
$error = 'You must make use of file in the following forma type png, gif, jpg, jpeg'; }
elseif($size>$size_maxi)
{
$error = 'File size is above allowed limitations...';
}
//If no error detected, proceed to upload 
else {
if (move_uploaded_file($_FILES["file"]["tmp_name"], $file)) {
    echo "The file ". basename( $_FILES["file"]["name"]). " has been    uploaded.";

     //Writes the information to the database
 mysql_query("INSERT INTO picture (P_file,P_type,P_size)
 VALUES ('$file', '$extension','$size')"); 
 } else {
    echo "Sorry, there was an error uploading your file.";
 }
}

}
D-Godwin
  • 11
  • 1
  • You can't do that with php, you need to use javascript to check the file before upload. – markt Jan 25 '17 at 23:03
  • can you help me javascript code to do that operation please? – D-Godwin Jan 25 '17 at 23:05
  • All you need is here: http://stackoverflow.com/questions/166221/how-can-i-upload-files-asynchronously#answers – markt Jan 25 '17 at 23:05
  • @D-Godwin, don't check just filename - it can be faked. Use [getimagesize](http://php.net/manual/en/function.getimagesize.php) function to check if it's really an image. – Vaviloff Jan 26 '17 at 05:32

0 Answers0