PHP for multi-File upload

Source: Internet
Author: User
Enough for a PHP implementation of multi-file upload example, direct code, thank you.


Reply to discussion (solution)

Why no one ....

Baidu swfupload, download a case study it
Multi-File upload is not a few lines of code to be clear.

Will single file upload not? It would be the same with many documents. Only the form control is named an array, and PHP handles arrays only.

$_files["File"] how to receive an array of files, I use
foreach ($_files["file"] as $item)
{
$s = $s. ",". $item;
}
Only one file can be received

What is your HTML code?

if ($_files[' file ' [' Size '] >0) {
if ($_files["file" ["error"] > 0) {
$msg = "Attachment upload error:". $_files["File" ["Error"];
}else{
if (file_exists ("upload/". $_files["File" ["Name"])) {
echo $msg =$_files["File" ["Name"]. "Attachment already exists! ";
}else{
$YC = $_post[' YC ');
$yt = $_post[' YT '];
$type = $_post[' type '];
$newFileName =str_replace (".", "_". Time (). ".", $_files["file" ["name"]);
$path = "upload/". $newFileName;
Move_uploaded_file ($_files["file"] ["Tmp_name"], $path);

$sql = "INSERT into A004 (C02,C03,C04,C05,C06,C07,C08,C09,C10) VALUES ('". $id. "', '". $newFileName. "', '". $path. "', '". $ Yc[0]. "', '". $YT [0]. "', '". $type [0]. "', ' 0 ', '". $_session[' login_id ']. "', '". Get_time ().
$msg = $DB->update ($sql, "[10016] failed to submit data, please try again later, or contact the technician! ");

//}
}
}








<title>jquery dynamic Add input type=file file upload domain</title>







for ($i =0; $i
This part is yours, and I'm not copying it, but I've added something.
$newFileName =str_replace (".", "_". Time (). ".", $_files["file" ["Name"] [$i]);
$path = "upload/". $newFileName;
Move_uploaded_file ($_files["file"] ["tmp_name"] [$i], $path);
}

But time () seems not enough, to Microtime (1) is basically enough

Try Uploadify.
A little change will be OK.

Https://github.com/valums/file-uploader
Recommended

for ($i =0; $i
This part is yours, and I'm not copying it, but I've added something.
$newFileName =str_replace (".", "_". Time (). ".", $_files["file" ["Name"] [$i]);
$path = "upload/". $newFileName;
Move_uploaded_file ($_files["file"] ["tmp_name"] [$i], $path);
}

But time () seems not enough, to Microtime (1) is basically enough

I just want to know how to receive multiple files in the background.

The code for the example is

Your upload control is
So $_files["file"][xxx] is an array (xxx = tmp_name,name,error,type,size)
Deal with it individually, of course, only error equals 0 is the successful upload

The code for the example is

Your upload control is
So $_files["file"][xxx] is an array (xxx = tmp_name,name,error,type,size)
Deal with it individually, of course, only error equals 0 is the successful upload

foreach ($_files[' file '] as $item)
{
echo Print_r ($item);
}
Why do you just get the first file?

Test code

 
  
After selecting two files
$_files Array After commit
Array
(
[File] = Array
(
[name] = = Array
(
[0] = i.jpg
[1] = Ico.zip
[2] = =
)

[Type] = = Array
(
[0] = Image/pjpeg
[1] = application/x-zip-compressed
[2] = =
)

[Tmp_name] = = Array
(
[0] = C:\Documents and settings\administrator\local settings\temp\php188.tmp
[1] = C:\Documents and settings\administrator\local settings\temp\php189.tmp
[2] = =
)

[ERROR] = Array
(
[0] = 0
[1] = 0
[2] = 4
)

[size] = = Array
(
[0] = 7198
[1] = 121062
[2] = 0
)

)

)

Go see for yourself.
  • 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.