Home > php教程 > php手册 > php中实现图片上传的实例代码

php中实现图片上传的实例代码

WBOY
Release: 2016-06-13 09:28:43
Original
782 people have browsed it

php中实现图片上传的实例代码

   以下是PHP中实现图片上传的实例代码,第一页是表单页upfiles_frm.php。

  代码

  标题:

  上传文件:

  第二页是处理表单页upfiles_add.php

  代码 1

  2 $mkdir_file_dir = mkdir('./img/'.$_POST['title'],0777);     //上传文件的时候就开始创建一个图片相关的目录

  3 $tmp_file_name = $_FILES['file']['tmp_name']; //上传成功之后取的临时文件名

  4 $file_name = $_FILES['file']['name']; //原始的文件名

  5

  6 $file_dir = './img/'.$_POST['title'].'/'; //把创建的一个目录赋值给你一个变量作为最终的保存目录

  7

  8 if(is_dir($file_dir))

  9 {

  10 move_uploaded_file($tmp_file_name,$file_dir.$file_name);        //开始移动文件

  11 }

  12 ?>

  //在文件目录下建立一个文件夹img

  再建立文件,在php环境下,再试试看!

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 Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template