php 文件上传
Posted 宝清老窖
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 文件上传的主要内容,如果未能解决你的问题,请参考以下文章