需要3个代码文件,action.php、index.html、jquery.form.js,代码可进去下面的链接页下载
代码详解参考http://www.helloweba.com/view-blog-189.html
我自己稍作修改,解除对上传的限制,路径也稍作修改下
<?php $action = $_GET['act']; if($action=='delimg'){ $filename = $_POST['imagename']; if(!empty($filename)){ unlink('files/'.$filename); echo '1'; }else{ echo '删除失败.'; } }else{ $picname = $_FILES['mypic']['name']; $picsize = $_FILES['mypic']['size']; if ($picname != "") { //if ($picsize > 1024000) { // echo '图片大小不能超过1M'; // exit; //} //$type = strstr($picname, '.'); //if ($type != ".gif" && $type != ".jpg") { // echo '图片格式不对!'; // exit; //} $rand = rand(100, 999); $pics = date("YmdHis") . $rand . $type; //上传路径 //$pic_path = "files/". $pics; $targetFolder = '/uploads'; $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder; $targetFile = rtrim($targetPath,'/') . '/' . $_FILES['mypic']['name']; move_uploaded_file($_FILES['mypic']['tmp_name'], $targetFile); } $size = round($picsize/1024,2); $arr = array( 'name'=>$picname, 'pic'=>$pics, 'size'=>$size ); echo json_encode($arr); } ?>
1、刚开始在ubuntu的apache+php的环境下测试
通过浏览器浏览http://localhost/upload/index.html,能够打开网页,但上传不了文件,查了很久,后来修改了apache端口,即可上传(default port 80 --->8001)
2、在arm-ubuntu的lighttpd+php的环境下测试
通过浏览器浏览http://localhost/upload/index.html,能够打开网页,但上传不了文件,根据上述经验,修改fastcgi端口
修改 conf.d/fastcgi.conf
fastcgi.server = ( ".php" => ( "localhost" => ( "socket" => "/opt/web/lighttpd.player.server.socket", "bin-path" => "/opt/php/bin/php-cgi", "max-procs" => 1, "check-local" => "disable" )) )
fastcgi.server = ( ".php" => ( "localhost" => ( # "socket" => "/opt/web/lighttpd.player.server.socket", "host" => "127.0.0.1", "port" => 1026, "bin-path" => "/opt/web/sbin/php-cgi", "max-procs" => 1, "check-local" => "disable" )) )
查看了lighttpd.conf(server.max-request-size ),没有限制上传文件的大小,奇怪,浏览器打开http://192.168.1.129/test.php
test.php
<?php phpinfo(); ?>
发现
upload_max_filesize = 2M
开始修改
修改在php下POST文件大小的限制
修改php.ini
post_max_size = 8M 改为 post_max_size = 20M
upload_max_filesize = 2M 改为 upload_max_filesize = 20M
memory_limit = 16M(默认为8M) 由于上传大文件比较费时,所以
max_execution_time 设为800
把php代码里面的默认值也修改成上述值
重新编译,把生成的php-cgi拷贝到 fastcgi.conf里面指定的bin-path路径。
ok
成功上传大文件到目标板系统上