PHP资料上传

WBOY
Release: 2016-06-13 10:29:50
Original
932 people have browsed it

PHP文件上传

必须确保服务器目标文件夹的属性为可写:chmod 777 -R dir

?

主要步骤:
1、根据网页中设定位置,自建一个用于存储文件的文件夹cyupload
2、修改cyupload的权限,进入/tmp文件夹中,chmod 777 cyupload -R
3、参考http://www.w3schools.com/php/php_file_upload.asp 的??? 代码,分别建立upload.html 和 upload.php
4、根据需求将upload.php中的判断语句修改
5、修改php.ini文件,修改上传文件大小限制。
file_uploads = on ;是否允许通过HTTP上传文件的开关。默认为ON即是开
upload_tmp_dir ;文件上传至服务器上存储临时文件的地方,如果没指定就会用系统默认的临时文件夹
upload_max_filesize = 200m ;望文生意,即允许上传文件大小的最大值。默认为2M
post_max_size = 200m ;指通过表单POST给PHP的所能接收的最大值,包括表单里的所有值。默认为8M
一般地,设置好上述四个参数后,上传但如果要上传>8M的大体积文件,只设置上述四项还一定能行的通。
进一步配置以下的参数
max_execution_time = 0 ;
max_input_time = 2400 ;每个PHP页面接收数据所需的最大时间默认60秒
memory_limit = 256m ;每个PHP页面所吃掉的最大内存,默认8M
把上述参数修改后,在网络所允许的正常情况下,就可以上传大体积文件了


详细代码:upload.html

<html><body><form. enctype="multipart/form-data"  action="up.php" method="post"><label for="file">Filename:</label><input type="file" name="file" id="file" /><br /><input type="submit" name="submit" value="upload"></form></body></html><!--enctype="multipart/form-data" 该属性在form中必须定义才能上传-->upload.php<?phpif ($_FILES["file"]["size"] < 210000000)  {  if ($_FILES["file"]["error"] > 0)    {    echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";    if (file_exists("/tmp/cyupload/" . $_FILES["file"]["name"]))      {      echo $_FILES["file"]["name"] . " already exists. ";      }    else      {      move_uploaded_file($_FILES["file"]["tmp_name"],      "/tmp/cyupload/" . $_FILES["file"]["name"]);      echo "Stored in: " . "/tmp/cyupload/" . $_FILES["file"]["name"];      }    }  }else  {  echo "Invalid file";  }?>
Copy after login

?

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