本站内容搜索:
   您的位置:素材中国>>教程 >>网络编程 >>PHP编程 >>PHP上传多个文件 提交错误报告
PHP上传多个文件
[ 来源:素材中国 | 作者:未知| 时间:2005-09-13 04:32:09 | 浏览:人次 ]

 
  您可以对 input 域使用不同的 name 来上传多个文件。 PHP 支持同时上传多个文件并将它们的信息自动以数组的形式组织。要完成这项功能,您需要在 HTML 表单中对文件上传域使用类似于多下拉菜单和复选框的数组名称来提交。 注: 对多文件上传的支持是在 3.0.10 版本添加的。 例子 18-3. 上传多个文件
Send these files:


当以上表单被提交后,数组 $_FILES['userfile']、$_FILES['userfile']['name'] 和 $_FILES['userfile']['size'] 将被初始化(在 PHP 4.1.0 以前版本是 $HTTP_POST_FILES。如果 register_globals 的设置为 on,则和文件上传相关的全局变量也将被初始化。)所有这些提交的信息都将被储存到以数字为索引的数组中。 例如,假设名为 /home/test/review.html 和 /home/test/xwp.out 的文件被提交,则 $_FILES['userfile']['name'][0] 将包含文件 review.html 的名称,而 $_FILES['userfile']['name'][1] 则将包含文件 xwp.out 的名称。类似的,$_FILES['userfile']['size'][0] 将包含文件 review.html 的大小,依此类推。 $_FILES['userfile']['name'][0]、$_FILES['userfile']['tmp_name'][0]、$_FILES['userfile']['size'][0] 以及 $_FILES['userfile']['type'][0] 都将被同时设置并有效。 User Contributed Notes 上传多个文件 muellerATfmiDOTuniDASHpassauDOTde 21-Jan-2003 12:42 if your HTML is right but the $_FILES / $HTTP_POST_FILES array is empty make sure your < form > tag includes enctype="multipart/form-data" cost me one hour to notice that. i hope i can save somebody valuable time by pointing out the obvious :-) quinten+spam at andrew dot cmu dot edu 26-Jun-2002 01:30 Here's working file upload code snippet that works for any number of files "out of the box." It assumes that each input of type file is named 'files[]', although this could be modified so that it just iterated through the array $HTTP_POST_FILES. It will not overwrite existing files. It could be improved with more checks (ie, mime types) but this does what I need quite admirably. Let me know if you find an inefficiency. Code: $path_to_file = '/var/www-uploads/'; $files = $HTTP_POST_FILES['files']; if (!ereg("/$", $path_to_file)) $path_to_file = $path_to_file."/"; foreach ($files['name'] as $key=>$name) { if ($files['size'][$key]) { // clean up file name $name = ereg_replace("[^a-z0-9._]", "", str_replace(" ", "_", str_replace("%20", "_", strtolower($name) ) ) ); $location = $path_to_file.$name; while (file_exists($location)) $location .= ".copy"; copy($files['tmp_name'][$key],$location); unlink($files['tmp_name'][$key]); echo "\n Successfully uploaded file: $name."; } } ken at gizzar dot com 15-May-2002 10:32 When you do a multiple file
upload via POST method, the most logical choice is to use the PHP array: . . .
You would get a few arrays if you had your register globals turned on: $uploads - an array of the tmp filenames & paths $uploads_name - an array of the name given by the browser $uploads_size - an array of the sizes $uploads_type - an array of the MIME types of the file uploaded So, if I looked at the content of $uploads_name["first"] in 'something.php' (in this case), it will give me the browser assigned name for the first file . Next, you should look at how PHP limits file sizes in php.ini! Have fun! -Ken fjeanson at yahoo dot com 20-Feb-2002 08:35 by the way to grab the pointer to which name="userfile[]" points at in the html
, all you need is $userfile[0] or $userfile[$i] at index $i. ex to upload a file: Code: Your file is way to big!!!
"; } fclose($fp); } ?>
 
 
       
   您的位置:素材中国>>教程 >>网络编程 >>PHP编程 >>PHP上传多个文件
 点此在百度搜索关键字"PHP上传多个文件"  点此在GOOGLE搜索关键字"PHP上传多个文件"
热门文章:
  ·PHP生成缩略图的实现   ·PHP上传多个文件
  ·PHP中发送邮件的几种方法总结   ·PHP 调用 java类 常见配置错误
  ·自己写的一个PHP上传类   ·php下的RSA算法实现
  ·PHP百行代码快速构建简易聊天室   ·PHP实现简单线性回归之数学库的重要性
  ·php5的simplexml解析错误   ·使用PHP批量生成随机用户名

  首页  素材图片  高精图库  矢量图库  网页素材  网页模板  壁纸  明星  下载  教程  字体  香车美女  QQ专题  论坛

网站介绍 | 广告业务 | 设计业务 | 免责声明 | 版权声明 | 联系我们|提交错误报告
素材中国版权所有