首页 > 代码库 > php 文件上传
php 文件上传
uploadForm.html
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <form action="upload_file.php" method="post" enctype="multipart/form-data"> <label for="fileName">fileName:</label> <input type="file" id="fileName" name="file" /><br /> <input type="submit" value="submit" /> </form> </body> </html>
upload_file.php
<?php //判断文件的类型,用户只能上传gif和jpeg的文件 if((($_FILES[‘file‘][‘type‘] == ‘image/gif‘)||($_FILES[‘file‘][‘type‘] == ‘image/jpeg‘)||($_FILES[‘file‘][‘type‘] == ‘image/pjpeg‘))&&($_FILES[‘file‘][‘size‘]<2000000)){ if($_FILES[‘file‘][‘error‘] > 0){ echo "Error:" . $FILES[‘file‘][‘error‘]. ‘<br/>‘; }else{ echo ‘Upload: ‘ . $_FILES[‘file‘][‘name‘].‘<br />‘; echo ‘Type: ‘ . $_FILES[‘file‘][‘type‘] . ‘<br />‘; echo ‘Size: ‘ . ($_FILES[‘file‘][‘size‘]/1024).‘Kb <br/>‘; echo ‘Stored in: ‘ . $_FILES[‘file‘][‘tmp_name‘] . ‘<br />‘; //判断是否存在 if(file_exists(‘upload/‘ . $_FILES[‘file‘][‘name‘])){ echo $_FILES[‘file‘][‘name‘]. ‘ is exist‘; }else{ move_uploaded_file($_FILES[‘file‘][‘tmp_name‘] , ‘upload/‘.$_FILES[‘file‘][‘name‘]); echo ‘successed‘; } } }else{ echo ‘fileType error or fileSize error‘; } ?>
php 文件上传
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。