php图片上传实现代码
先了解files函数
$_files数组内容如下:
$_files['myfile']['name'] 客户端文件的原名称。
$_files['myfile']['type'] 文件的 mime 类型,需要浏览器提供该信息的支持,例如"image/gif"。
$_files['myfile']['size'] 已上传文件的大小,单位为字节。
$_files['myfile']['tmp_name'] 文件被上传后在服务端储存的临时文件名,一般是系统默认。可以在php教程.ini的upload_tmp_dir 指定,但 用 putenv() 函数设置是不起作用的。
$_files['myfile']['error'] 和该文件上传相关的错误代码。['error'] 是在 php 4.2.0 版本中增加的。下面是它的说明:(它们在php3.0以后成了常量)
upload_err_ok
值:0; 没有错误发生,文件上传成功。
upload_err_ini_size
值:1; 上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值。
upload_err_form_size
值:2; 上传文件的大小超过了 html 表单中 max_file_size 选项指定的值。
upload_err_partial
值:3; 文件只有部分被上传。
upload_err_no_file
值:4; 没有文件被上传。
值:5; 上传文件大小为0.
php代码
$mkdir_file_dir = mkdir('./img/'.$_post['title'],0777); //上传文件的时候就开始创建一个图片相关的目录
$tmp_file_name = $_files['file']['tmp_name']; //上传成功之后取的临时文件名
$file_name = $_files['file']['name']; //原始的文件名
$file_dir = './img/'.$_post['title'].'/'; //把创建的一个目录赋值给你一个变量作为最终的保存目录
if(is_dir($file_dir))
{
move_uploaded_file($tmp_file_name,$file_dir.$file_name); //开始移动文件
}
?>
html代码
my is upfile app!!
非常重要的一点是:文件通过post提交后是保存在c:windowstemp临时文件夹中通过$_files["photo"]["tmp_name"],我们可以轻松获得上传的临时文件,将它保存到我们指定的路径中 下面是解决方案move_uploaded_file($_files["photo"]["tmp_name"],$path)

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Chinese version
Chinese version, very easy to use

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

Zend Studio 13.0.1
Powerful PHP integrated development environment

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool
