Php multi-file Upload

Source: Internet
Author: User
Tags php file upload setcookie
The code is as follows: Copy code

<! Doctype html public "-// w3c // dtd xhtml 1.0 transitional // en" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<Html xmlns = "http://www.w3.org/1999/xhtml">
<Head>
<Meta http-equiv = "content-type" content = "text/html; charset = gb2312"/>
<Title> php file Upload </title>
</Head>

<Body>
<Form action = "" method = "post" enctype = "multipart/form-data" name = "form1" id = "form1">
<P>
<Label for = "select"> </label>
<Label for = "filefield"> </label>
<Input type = "file" name = "name []" id = "filefield"/>
</P>
<P>
<Input type = "file" name = "name []" id = "filefield2"/>
</P>
<P>
<Input type = "file" name = "name []" id = "filefield3"/>
</P>
<P>
<Input type = "file" name = "name []" id = "filefield4"/>
</P>
<P>
<Input type = "file" name = "name []" id = "filefield5"/>
</P>
<P>
<Input type = "submit" name = "button" id = "button" value = "batch file upload"/>
</P>
</Form>
</Body>
</Html>

<? Php

Foreach ($ _ files as $ f)
{
// Process the Chinese name
If (function_exists ("iconv") $ f [name] = iconv ("UTF-8", "gb2312", $ f [name]);

$ Unm = intval (mt_rand (1000,9999 ));
$ File = "z_upload/". date ("ymdhms"). $ unm. $ f [name];

// Check whether a file with the same name already exists
If (file_exists ($ file) header ("http/1.0 403 ");
// Save the file
 
If (! @ Move_uploaded_file ($ f ["tmp_name"], $ file ))
 {
Header ("http/1.0 404 not found ");
} Else {
If (! Isset ($ _ cookie ['uploadpic ']) {
Setcookie ("uploadpic", $ file );
} Else {
Unlink ($ _ cookie ['uploadpic ']);
Setcookie ("uploadpic ","");
Setcookie ("uploadpic", $ file );
}
Echo "1 ";
 
 }
}
?>

Related Article

E-Commerce Solutions

Leverage the same tools powering the Alibaba Ecosystem

Learn more >

Apsara Conference 2019

The Rise of Data Intelligence, September 25th - 27th, Hangzhou, China

Learn more >

Alibaba Cloud Free Trial

Learn and experience the power of Alibaba Cloud with a free trial worth $300-1200 USD

Learn more >

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.