简单的PHP多图上传小程序代码_php技巧

WBOY
Release: 2016-05-17 09:16:58
Original
1976 people have browsed it

先上源代码,你可以copy到自己的电脑上去运行~

复制代码代码如下:




多文件上传


















//上传文件信息
$img = $_FILES['img'];
if ($img)
{
//文件存放目录,和本php文件同级
$dir = dirname(__file__);
$i = 0;
foreach ($img['tmp_name'] as $value)
{
$filename = $img['name'][$i];
if ($value)
{
$savepath="$dir\\$filename";
$state = move_uploaded_file($value, $savepath);
//如果上传成功,预览
if($state)
{
echo " $filename";
}
}
$i++;
}
}
?>



move_uploaded_file() 函数
move_uploaded_file() 函数将上传的文件移动到新位置。若成功,则返回 true,否则返回 false。
用法:move_uploaded_file(file,newloc)
参数 file,必需。规定要移动的文件。
参数 newloc,必需。规定文件的新位置。
本函数检查并确保由 file 指定的文件是合法的上传文件(即通过 PHP 的 HTTP POST 上传机制所上传的)。如果文件合法,则将其移动为由 newloc 指定的文件。
如果 file 不是合法的上传文件,不会出现任何操作,move_uploaded_file() 将返回 false。
如果 file 是合法的上传文件,但出于某些原因无法移动,不会出现任何操作,move_uploaded_file() 将返回 false,此外还会发出一条警告。
这种检查显得格外重要,如果上传的文件有可能会造成对用户或本系统的其他用户显示其内容的话。
注释:本函数仅用于通过 HTTP POST 上传的文件。
注意:如果目标文件已经存在,将会被覆盖。
Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!