004-PHP image upload example

不言
Release: 2023-03-23 10:12:01
Original
1390 people have browsed it

The content introduced in this article is an example of PHP image uploading. Now I share it with everyone. Friends in need can refer to it


<!DOCTYPE html>
<html lang="en">
<head>
	<meta charset="UTF-8">
	<title>Document</title>
</head>
<body>
	<form action="03.php" method="post" enctype="multipart/form-data">
		<p>
			图片:
			<input type="file" name="pic" id="">
		</p>
		<input type="submit" value="提交">
	</form>
</body>
</html>
Copy after login
<?php 

//print_r($_FILES);
//将临时文件 移动到其他的位置

//生成随机文件名
$fname = rand(10000,99999);

//获取文件后缀
$ext = strrchr($_FILES[&#39;pic&#39;][&#39;name&#39;], &#39;.&#39;);//.jpg

//创建目录
$path = &#39;./&#39;.date(&#39;Y/m/d&#39;);
if(!is_dir($path)) {
	mkdir($path , 0777 , true);
}

//move_uploaded_file 移动上传文件
echo move_uploaded_file($_FILES[&#39;pic&#39;][&#39;tmp_name&#39;], $path . &#39;/&#39; . $fname . $ext)?&#39;ok&#39;:&#39;fail&#39;;

//2015/01/25/hua.jpg


?>
Copy after login


Related recommendations:

001 - Detailed analysis of PDO usage

002 - Differences and choices between PDO and MySQLi

003 - CI in Use CodeIgniter resources in your class library

The above is the detailed content of 004-PHP image upload example. For more information, please follow other related articles on the PHP Chinese website!

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
Popular Tutorials
More>
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!