警告:fopen()要求参数1为字符串,在第47行的/home/speedycm/public_html/speedyautos/carphoto.php中给出数组

时间:2011-03-11 01:48:48

标签: php

  

可能重复:
  mysql_fetch_array() expects parameter 1 to be resource, boolean given in select

我正在尝试在我正在处理的网站上传jpeg图像,但一直收到以下错误:

Warning: fopen() expects parameter 1 to be string, array given in /home/speedycm/public_html/speedyautos/carphoto.php on line 47
Warning: filesize() [function.filesize]: stat failed for Array in /home/speedycm/public_html/speedyautos/carphoto.php on line 48
Warning: fread(): supplied argument is not a valid stream resource in /home/speedycm/public_html/speedyautos/carphoto.php on line 48
Warning: fclose(): supplied argument is not a valid stream resource in /home/speedycm/public_html/speedyautos/carphoto.php on line 49

文件carphoto.php在第47-49行

上有以下代码
    $fp = fopen($_FILES["pics"]["tmp_name"], 'rb'); 
$contents = fread($fp, filesize($_FILES["pics"]["tmp_name"]));  
fclose($fp);

提前感谢你

1 个答案:

答案 0 :(得分:3)

这通常是因为您在html表单中使用多个文件上传并使用数组将它们组合在一起。像:

<input type="file" name="pics[]"> ...

因此,php会将这些tmp_files分组到一个数组中。

您可能希望单独引用它们

foreach($_FILES["pics"]["tmp_name"] as $file) {
      ....
}