search

Home  >  Q&A  >  body text

The sample code is incorrect and the file format is incorrect, line 51.

<?php

//Judge error code

require("upload.html");


##if( $_FILES['file']['error']>0){

switch($_FILES['file']['error']){

case '1':

echo 'The file is too large';

break;

case '2':

echo 'The file exceeds the specified size ';

                                                                                                                                        break; case '4':

echo 'The file was not uploaded';

break;

case '6':

echo 'The specified file cannot be found Folder';

                                                                                                                                                                                                       break; # default:

echo 'Upload error</br>';

}

}else{

if( $_FILES['file']['size']>200000){

exit("The file exceeds the specified size");

}

//Judge the file suffix name

$allowsuffix = array('png','jpg','jpeg');

$filename = explode(' .',$_FILES['file']['name']);

$filesuffix = array_pop($filename);

if(!in_array($filesuffix,$allowsuffix)) {

exit("The file suffix is ​​incorrect");

}

$allowmine = array(

"image/ png",

"image/jpg",

"image/jpeg",

"image/pjpeg",

"image/gif" ,

);

if(!in_array($_FILES['file']['name'],$allowmine)){

exit("The file format is not Correct");

}

//Specify the upload file path

$path = "d:/phpstudy/ PHPtutorial/www/upload/image/";

$newname = date('YmdHis').rand(0,9).'.'.$filesuffix;

$filepath = $ path.$newname;

if(is_uploaded_file($_FILES['file']['tmp_name'])){

if(move_uploaded_file($_FILES['file']['tmp_name '],$filepath)){

echo "Upload successful";

}else{

echo "Upload failed";

}

}else{

echo"Upload error";

}

}

##?> ;

  2610 days ago1568

reply all(2)I'll reply

  • phpcn_u102508

    phpcn_u1025082018-02-04 19:55:27

    There is an extra number at the end of the array,

    reply
    1
  • 韦小宝

    韦小宝2018-01-31 09:22:02

    I don’t understand, what’s the error? Line 51

    reply
    0
  • Cancelreply