php: 파일 시스템 ③
풀어 주다: 2016-07-30 13:31:24
<!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";
}
위 내용은 내용의 측면을 포함하여 php: 파일 시스템을 소개합니다. PHP 튜토리얼에 관심이 있는 친구들에게 도움이 되기를 바랍니다.
본 웹사이트의 성명
본 글의 내용은 네티즌들의 자발적인 기여로 작성되었으며, 저작권은 원저작자에게 있습니다. 본 사이트는 이에 상응하는 법적 책임을 지지 않습니다. 표절이나 침해가 의심되는 콘텐츠를 발견한 경우 admin@php.cn으로 문의하세요.
저자별 최신 기사
-
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