Home > Backend Development > PHP Tutorial > PHP实现上传文件,该怎么处理

PHP实现上传文件,该怎么处理

WBOY
Release: 2016-06-13 12:26:57
Original
807 people have browsed it

PHP实现上传文件
写一段代码实现上传文件根据上传过来的rid和uid来自动创建文件夹,第一层文件夹命名就是rid名称,第二层则为uid名称 例如rid为5,uid=1 则文件夹为5/1  就是说5文件夹里面有1文件夹 ,上传的文件保存名称为原来上传的文件名不变   
------解决思路----------------------
client.html

<br /><html><br /><head><br /><title>upload test</title><br /></head><br /><br /><body><br /><form name="form1" method="post" action="server.php" enctype="multipart/form-data"><br /><p>图片:<input type="file" name="photo"></p><br /><p>rid:<input type="text" name="rid" value="5"></p><br /><p>uid:<input type="text" name="uid" value="1"></p><br /><input type="submit" name="b1" value="submit"><br /></form><br /><br /></body><br /></html><br />
Copy after login


server.php
<br /><?php<br />$rid = isset($_POST['rid'])? $_POST['rid'] : '';<br />$uid = isset($_POST['uid'])? $_POST['uid'] : '';<br /><br />if($rid=='' <br><font color='#FF8000'>------解决思路----------------------</font><br> $uid==''){<br />    exit('rid or uid error');<br />}<br /><br />$folder = $rid.'/'.$uid;<br /><br />mkdir($folder,0777,true);<br /><br />$tmp_name = $_FILES["photo"]["tmp_name"];<br />$name = $_FILES["photo"]["name"];<br />move_uploaded_file($tmp_name, $folder.'/'.$name);<br /><br />echo 'success';<br /><br />?><br />
Copy after login

------解决思路----------------------
echo  base64_encode(file_get_contents("php://input")); 

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