php文件上传简单实现方法,
本文实例讲述了php文件上传的简单实现方法。分享给大家供大家参考。具体如下:
文件1:index.php
复制代码 代码如下:
文件2:uploadProcess.php
复制代码 代码如下:
$filetype_arr = array("image/jpeg","image/png","image/gif","image/gif");//允许上传的图片类型
if(!empty($_POST['sub'])){
$username = $_POST['username'];//用户名
$password = $_POST['pwd'];//密码
if(is_uploaded_file($_FILES['upimage']['tmp_name'])){//判断是否是通过http上传的图片
$tmp_name = $_FILES['upimage']['tmp_name'];//上传图片临时名
//判断图片类型是否支持
if(!in_array($_FILES['upimage']['type'],$filetype_arr)){
echo "抱歉,上传图片只支持";
foreach($filetype_arr as $value){
echo $value.",";
}
echo "等类型";
exit();
}
$exten_name = substr($_FILES['upimage']['name'],strrpos($_FILES['upimage']['name'],"."));//获取上传图片的后缀名
$dest_name = $_SERVER['DOCUMENT_ROOT']."/php/upfile/".$username."/";//
//判断保存的目录是否存在,不存在则创建
if(!file_exists($dest_name)){
if(!mkdir($dest_name)){//如果创建不成功
echo "创建目录失败,文件无法上传";
exit();
}
}
//如果已经存在保存的目录
if(move_uploaded_file($tmp_name,$dest_name.time().rand(1,100).$exten_name)){//移动临时文件到保存的目录,并改名
echo "上传图片成功";
}else{
echo "图片上传失败";
}
}else{
echo "找不到你上传的图片,请重新上传";
}
}
?>
希望本文所述对大家的php程序设计有所帮助。

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

SublimeText3 Linux new version
SublimeText3 Linux latest version

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

ZendStudio 13.5.1 Mac
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

Notepad++7.3.1
Easy-to-use and free code editor
