This upload code, what is the problem???
This upload code, there is no limit upload file size, but now upload more than 100K is always unable to upload, the problem is where AH?
I want to limit, can only upload files within 500K, how to change?
$allow _type=array ("m4r", "jpg");//The type of picture allowed to upload
$name =$_files[' upimg ' [' name ']; The original name of the client file
$upload _dir= "upload/";//Picture Save Directory
Strtolower converting a string to lowercase
$file _suffix=strtolower (Getfilesuffix ($name));
if (!in_array ($file _suffix, $allow _type))
{
Implode combining array elements into strings
$all _type=implode (",", $allow _type);
Exit ("");
}
Explode splitting a string into arrays
$name _array=explode (".", $name);
Do
{
$name _array[0]=randomfilename ();
$name =implode (".", $name _array);
$upload _file= $upload _dir. $name;
}while (file_exists ($upload _file));
$tmp _name=$_files[' upimg ' [' tmp_name '];
Is_uploaded_file to determine if the file was uploaded via HTTP post
if (Is_uploaded_file ($tmp _name))
{
Move_uploaded_file moving uploaded files to the specified directory
if (Move_uploaded_file ($tmp _name, $upload _file))
{
echo "$upload _file songs uploaded successfully! ";
Exit ("");
}
}
Get file suffix name
function Getfilesuffix ($fileName)
{
STRRCHR returns the last occurrence of any character in $filename to the end. substr and remove '. '
Return substr (STRRCHR ($fileName, '. '), 1);
}
Generate Random file names
function Randomfilename ()
{
Turn time zone to Beijing time, php5 default to Greenwich Mean Time
Date_default_timezone_set ("PRC");
Return date (' Ymdhis '). Rand (100,999);
}
?>
------Solution--------------------
1, more than 100K of files can not be uploaded, please take a look at the value of $_files[' upimg ' [' Error '], there are several possible situations:
A value of 1 indicates that the file size exceeds the upload_max_filesize defined in php.ini;
A value of 2 indicates that the file size exceeds the limit in HTML. The file size can be restricted in HTML by the following code:
HTML code
!--limit file size not exceeding 100kb-->
------solution--------------------
can be judged in PHP!
if ($_files[' upimg ' [' Size ']>1024*500)
{
echo ' file exceeded 500k, no upload! ";
Exit;
}
As for the inability to upload, my personal estimate is:
do
{
$name _array[0]=randomfilename ();
$name =implode (".", $name _array);
$upload _file= $upload _dir. $name;
}while (file_exists ($upload _file)); The
file exists before the $upload_file= $upload _dir. $name; the fact that the file does not exist at the first time, the code does not execute at all, that is to say: $upload _file cannot truly reflect its file path, Then move_uploaded_file in the back of the time will not be able to execute.