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

i keep getting these error messages whenever trying to upload a picture on my website and i'm not sure how to sort them out. can anyone please help? lines 36-59 read:

$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]);

many thanks in advance!

Member Avatar for langsor

If you do a

print_r($_FILES["pics"]["tmp_name"]);

I'm sure you'll see that it is an array as passed in through multiple form values <input name="photo[]" /> or similar.

In other words,
Here you treat it like an array

is_uploaded_file($_FILES['pics']['tmp_name'][$ctrP])

and here you treat it like a string, but clearly it's an array -- and that is the cause of your errors

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

* A side note. When submitting a question it is useful, to both the answerer and also yourself, to reduce the problem into the simplest possible example (not just copy/paste directly from your code). Often this will be enough to solve the answer on your own, but even if not, will make it easier to read the situation. Tnx.

Member Avatar for diafol

I'm confused:

you do this: foreach ($_FILES as $pics)

but keep on using $_FILES in your loop code. Surely you want to be using $pics?

e.g.

if ($pics['name'][$ctrP] <> "")

If have to say I don't understand the need for [$ctrP]

Is this supposed to relate to a array item counter? If so, you don't need it as $pics is already doing the loop.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.