Home >Backend Development >PHP Tutorial >php中图片上传

php中图片上传

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOriginal
2016-05-19 12:16:02872browse

第一页是表单页upfiles_frm.php

<html>    <head>        <title>            my is upfile app!!        </title>        <meta    http-equiv="content-type" content="text/html;charset=utf-8" />    </head>    <body>        <form enctype="multipart/form-data" method="post" action="upfile_add.php">                标题:     <input type="text" name="title" />                上传文件: <input type="file" name="file" />                <input type="submit" vlaue="提交" />        </form>    </body></html>

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

<?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);   
//开始移动文件
}
?>

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

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

Statement:
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