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>
<?php //print_r($_FILES); //将临时文件 移动到其他的位置 //生成随机文件名 $fname = rand(10000,99999); //获取文件后缀 $ext = strrchr($_FILES['pic']['name'], '.');//.jpg //创建目录 $path = './'.date('Y/m/d'); if(!is_dir($path)) { mkdir($path , 0777 , true); } //move_uploaded_file 移动上传文件 echo move_uploaded_file($_FILES['pic']['tmp_name'], $path . '/' . $fname . $ext)?'ok':'fail'; //2015/01/25/hua.jpg ?>
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!