尝试上传图片时反复出现警告

时间:2011-03-22 02:14:31

标签: php

Warning: fopen() expects parameter 1 to be string, array given in /home/speedycm/public_html/speedyautos/carphoto.php on line 42

Warning: filesize() [function.filesize]: stat failed for Array in /home/speedycm/public_html/speedyautos/carphoto.php on line 43

Warning: fread(): supplied argument is not a valid stream resource in /home/speedycm/public_html/speedyautos/carphoto.php on line 43

Warning: fclose(): supplied argument is not a valid stream resource in /home/speedycm/public_html/speedyautos/carphoto.php on line 44

我每次尝试在我的网站上传图片时都会收到这些错误消息,而我不确定如何对其进行排序。有人可以帮忙吗?第36-59行:

$CarInfo->Load();
if ($hidaction == "addphoto")
{
    $ctrP = 0;
    foreach ($_FILES['pics'] as $pics)
    {
        if ($_FILES['pics']['name'][$ctrP] <> "")
        {
            if (is_uploaded_file($_FILES['pics']['tmp_name'][$ctrP]) or die("No Image: " . $_FILES['pics']['name'][$ctrP]))
            {
                $ext = substr(strrchr($_FILES['pics']['name'][$ctrP], "."), 1);
                $fp = fopen($_FILES["pics"]["tmp_name"], 'rb');
                $contents = fread($fp, filesize($_FILES["pics"]["tmp_name"]));
                fclose($fp);
                if (preg_match("/system/", $contents) OR preg_match("/<\?/", $contents))
                {
                    $error .= "Invalid image: {$_FILES['pics']['name'][$ctrP]}<br />";
                    //$pieces = explode(".", $_FILES['pics']['name'][$ctrP]);
                    //$ext = $pieces[count($pieces) - 1];
                } elseif ((in_array($ext, $types_array)) AND ($_FILES['pics']["size"][$ctrP] < (MAXFILE_SIZE * 1000000)))
                {
                    $orgImageName = "cid" . $property_id . "_" . str_replace(" ", "_", $_FILES['pics']['name'][$ctrP]);
                    $thmImageName = "thumb_cid" . $property_id . "_" . str_replace(" ", "_", $_FILES['pics']['name'][$ctrP]);
                    $dtlImageName = "dtl_cid" . $property_id . "_" . str_replace(" ", "_", $_FILES['pics']['name'][$ctrP]);

非常感谢提前和抱歉btw: - )

2 个答案:

答案 0 :(得分:2)

我不是一个PHP人,但它看起来好像_FILES是一个三维字符串数组。有时您使用三个索引:

$ _ FILES [ '图片'] [ 'tmp_name的值'] [$ CTRP]

但是在fopen()调用中,你只使用两个;这意味着你将一维字符串数组传递给fopen(),这是错误的。在这一行上你需要第三个索引:

$ fp = fopen($ _ FILES [“pics”] [“tmp_name”],'rb');

答案 1 :(得分:1)

您忘记正确引用加载到导致错误的行中上传的$ _FILES数组中的多个图像。

你在哪里:

$fp = fopen($_FILES["pics"]["tmp_name"], 'rb');
$contents = fread($fp, filesize($_FILES["pics"]["tmp_name"]));

应该是这样的:

$fp = fopen($_FILES["pics"]["tmp_name"][$ctrP], 'rb');
$contents = fread($fp, filesize($_FILES["pics"]["tmp_name"][$ctrP]));

你发送的是一个数组($_FILES["pics"]["tmp_name"])到一个需要一个字符串的函数中,该字符串应该是从数组中取出的值($_FILES["pics"]["tmp_name"][$ctrP])。