单张的图片上传是不复杂的,这里涉及到多张图片上传和对图片格式的校验,保证上传的一定是图片,防止上传其他文件到服务器。
基本实现算法是使用数组的形式,把所有的图片提交个一个数组,对数组的元素进行一个个的处理。
以下为引用的内容:
// 图片目录
$img_dir = "../upload/";
// …… html 显示上传界面
/* 图片上传处理 */
// 把图片传到服务器
// 初始化变量
$uploaded = 0;
$unuploaded = 0;
//只允许五张图片上传
for ($i=0; $i
{
//获取当前图片的信息
$is_file = $_FILES['imgfile']['name'][$i];
//如果当前图片不为空
if (!empty($is_file))
{
//把当前图片的信息存储到变量里
$result[$i] = "
". $_FILES['imgfile']['name'][$i] ."
". round($_FILES['imgfile']['size'][$i]/1024, 2) ."K
". $_FILES['imgfile']['type'][$i] ."
";
// 判断上传的图片的类型是不是jpg,gif,png,bmp中的一种,同时判断是否上传成功
if (
$_FILES['imgfile']['type'][$i] == "image/pjpeg" ||
$_FILES['imgfile']['type'][$i] == "image/gif" ||
$_FILES['imgfile']['type'][$i] == "image/x-png" ||
$_FILES['imgfile']['type'][$i] == "image/bmp"
)
{
//如果上传的文件没有在服务器上存在
if (!file_exists($img_dir . $_FILES['imgfile']['name'][$i]))
{
//把图片文件从临时文件夹中转移到我们指定上传的目录中
move_uploaded_file($_FILES['imgfile']['tmp_name'][$i],
$img_dir . $_FILES['imgfile']['name'][$i]);
$result[$i] .= "成功";
$uploaded++;
}
else //如果文件已经在服务器上存在
{

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Safe Exam Browser
Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.