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.