PHP implementation of large file upload source code

Source: Internet
Author: User
Tags chmod file upload trim

Classic PHP Implementation of large file upload source code:

A more classic php large file upload source code, can be successfully run.

function Function_upload ($name, $newname = "", $dir = "Upload")
{
Global $_files, $ext;

$return = "";

$time =time ();

$upload =trim ($_files[$name] [' tmp_name ']);

$upload _name=trim ($_files[$name] [' name ']);

$size =trim ($_files[$name] [' size ']);

if (empty ($upload) or empty ($upload _name) or $size ==0)
{
return $return;
}

$dir. = "/". Date ("Y-m", $time);

if (Is_uploaded_file ($upload))
{
$ext =file_extension ($upload _name);

if (Liu_mkdir ($dir))
{

if ($newname!= "")
{

$newname. = ".". $ext;
$newname =time_now. "." $ext;
}else{
$newname = $upload _name;
$newname = $time. ". $ext;
}

if (Move_uploaded_file ($upload, $dir.) /". $newname) and File_exists ($dir." /". $newname))
{
chmod ($dir. " /". $newname, 0755);
$return = $dir. " /". $newname;
}
}

}

return $return;

}

function File_extension ($filename)
{
Return substr (STRRCHR ($filename, '. '), 1);
}

function Liu_mkdir ($dir, $mode =0777)
{
if (Is_dir ($dir))
{

if (!is_writable ($dir))
{

@chmod ($dir, $mode);

}
return true;
}
Else

{

$oldmask = @umask (0);

$partialpath = DirName ($dir);

if (!liu_mkdir ($partialpath, $mode))
{

return false;

}
Else

{
return mkdir ($dir, $mode);
}

}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.