php: file system ③
Release: 2016-07-30 13:31:24
Original
901 people have browsed it
<!DOCTYPE <span>html</span>>
<<span>html </span><span>lang=</span><span>"en"</span>>
<<span>head</span>>
<<span>meta </span><span>charset=</span><span>"UTF-8"</span>>
<<span>title</span>><span>VIEW</span></<span>title</span>>
<<span>link </span><span>rel=</span><span>"stylesheet" </span><span>href=</span><span>"???" </span><span>type=</span><span>"text/css" </span>/>
</<span>head</span>>
<<span>body</span>>
<<span>div </span><span>class=</span><span>"register"</span>>
<span><!--</span><span宋体'">文件编码类型</span><span>enctype;--->
</span><span></span><<span>form </span><span>enctype=</span><span>"multipart/form-data" </span><span>method=</span><span>"post" </span><span>action=</span><span>"uploadprocess.php" </span><span>name=</span><span>"myform"</span>>
<<span>table</span>>
<<span>tr</span>><<span>td </span><span>align=</span><span>"center" </span><span>colspan=</span><span>"2"</span>><<span>font </span><span>style=</span><span>"</span><span><em>font-size</em></span>: <span>40</span><span>px</span>;<span><em>font-family</em></span>:<span宋体'">华文彩云</span>;<span>"</span>>
<span>文件上传
</span><span></span></<span>font</span>></<span>td</span>></<span>tr</span>>
<<span>tr</span>><<span>td</span>><span>请输入用户名:</span></<span>td</span>><<span>td</span>><<span>input </span><span>type=</span><span>"text" </span><span>name=</span><span>"username" </span>/> </<span>td</span>></<span>tr</span>>
<<span>tr</span>><<span>td</span>><span>请简单介绍该文件</span></<span>td</span>><<span>td</span>><<span>textarea </span><span>rows=</span><span>"10" </span><span>cols=</span><span>"40" </span><span>name=</span><span>"fileintro" </span>>
</<span>textarea</span>></<span>td</span>></<span>tr</span>>
<<span>tr</span>><<span>td</span>><span>请选择上传的文件:</span></<span>td</span>><<span>td</span>><<span>input </span><span>type=</span><span>"file" </span><span>name=</span><span>"myfile" </span>/> </<span>td</span>></<span>tr</span>>
<<span>tr</span>><<span>td</span>><<span>input </span><span>type=</span><span>"submit" </span><span>value=</span><span>"</span><span宋体'">上传</span><span>"</span>></<span>td</span>><<span>td</span>> </<span>td</span>></<span>tr</span>>
</<span>table</span>>
</<span>form</span>>
</<span>div</span>>
</<span>body</span>>
</<span>html</span>><precourier new font-size:16.5pt><img src="http://image.codes51.com/Article/image/20150816/20150816164640_4278.jpg" alt=""><precourier new font-size:16.5pt><precourier new font-size:16.5pt><span><?php
</span>$username<span>=</span>$_POST[<span>'username'</span>];
$fileintro<span>=</span>$_POST[<span>'fileintro'</span>];
<span>echo </span>$username<span>.</span>$fileintro;
<span>echo </span><span>"<pre class="brush:php;toolbar:false">"</span>;
<span><em>print_r</em></span>($_FILES);
<span>echo </span><span>"";
//上传大文件时,需在php.ini中修改post_max_size和upload_max_filesize参数;
$user_path=$_SERVER['DOCUMENT_ROOT']."/Hanshunping/UP/".$username;
$user_path=iconv("utf-8","gb2312",$user_path);
if(!file_exists($user_path)){
mkdir($user_path);
}
$fileName=$_FILES['myfile']['name'];
$fileName=iconv("utf-8","gb2312",$fileName);
if(is_uploaded_file($_FILES['myfile']['tmp_name'])){
$uploaded_file=$_FILES['myfile']['tmp_name'];
//避免同一用户上传的同一名字文件被覆盖;
$move_to_file=$user_path."/".time().rand(1,1000).
substr($fileName,strrpos($fileName,"."));
if(move_uploaded_file($uploaded_file,$move_to_file)){
echo $_FILES['myfile']['name']."上传OK";
}else{
echo "上传失败";
}
}else{
echo "FAILED";
}
The above introduces php: file system ③, including aspects of the content. I hope it will be helpful to friends who are interested in PHP tutorials.
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
Latest Articles by Author
-
2024-10-22 09:46:29
-
2024-10-13 13:53:41
-
2024-10-12 12:15:51
-
2024-10-11 22:47:31
-
2024-10-11 19:36:51
-
2024-10-11 15:50:41
-
2024-10-11 15:07:41
-
2024-10-11 14:21:21
-
2024-10-11 12:59:11
-
2024-10-11 12:17:31