Home > php教程 > php手册 > php初学者用文件上传实例

php初学者用文件上传实例

WBOY
Release: 2016-05-25 16:57:04
Original
929 people have browsed it

表单部分:
代码如下:

<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>
Copy after login

2,处理表单页面:
代码如下:

<?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_url = $file_dir.$file_name; 
$link = mysql教程_connect("localhost","root",""); 
mysql_select_db("fenye"); 
mysql_query("set names utf8"); 
$insert = "insert into upfiles(title,img_url) values ('{$_post['title']}','{$img_url}') "; 
mysql_query($insert); //把文件路径存放到数据库教程中 
} 
Copy after login

文章网址:

随意转载^^但请附上教程地址。

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