Page 2 of 2

Re: Upload Function Issue

Posted: Thu Dec 23, 2010 2:00 pm
by jzmwebdevelopment
I got
Array
(
)
1$_FILES:

ImagePath:

Should I access it by going ['imagePath']['name']?

Re: Upload Function Issue

Posted: Thu Dec 23, 2010 2:05 pm
by ccsdg
That's the right idea! I'm not sure exactly about PHP syntax for nested arrays, so I would personally get out the ImagePath array in its own variable first:

Code: Select all

$tempImagePathArray = $_FILES['ImagePath'];
and then out of that array, get out the 'name' item:

Code: Select all

$name = $tempImagePathArray['name'];
HTH

EDIT: your arrays look empty, though i'm assuming you truncated them for convenience. If they're actually empty, check you've uploaded a file first.

Re: Upload Function Issue

Posted: Thu Dec 23, 2010 2:20 pm
by jzmwebdevelopment
Thats the issue,

I can get it to save the path to the db but not upload the file. I no the array is empty but I cannot work out why :(.

How would I call $temp?

Re: Upload Function Issue

Posted: Thu Dec 23, 2010 2:38 pm
by ccsdg
1. The $_FILES array will be empty if you have not uploaded a file. Remember you had this:

Code: Select all

Array
(
    [ImagePath] => Array
        (
            [name] => Corn.jpg
            [type] => image/jpeg
            [tmp_name] => /tmp/phpz8Emls
            [error] => 0
            [size] => 72068
        )

)
That shows there was a file there. At the moment it seems you haven't attempted to upload a file yet (or it's exceeded the size limits, but I doubt that).

2. uploading the file requires taking the tmp_name and the target name (including the path), then passing them both to the move_uploaded_file() function (in that order). check out the php documentation if you haven't already. http://php.net/manual/en/function.move- ... d-file.php

3. If you have something in your files array you will be able to access it with either $_FILES['ImagePath']['name'] or the temporary array syntax i posted. If you can't access it at all, it'll most likely be because there's nothing in there.

Re: Upload Function Issue

Posted: Thu Dec 23, 2010 4:29 pm
by jzmwebdevelopment
2. I have looked and looked again

3. I have just print_r and got Corn.jpg

echo '<pre>',
print_r($_FILES['ImagePath']['name']);

echo '</pre>';

I just cannot work out why its not saving

Re: Upload Function Issue

Posted: Thu Dec 23, 2010 4:39 pm
by ccsdg
So your move_uploaded_file() function has those 2 variables correctly passed in?

EDIT: by that i mean, try echoing those two variables out and see if they are what they should be

Print_r: that's good, as long as it's not empty :)

Re: Upload Function Issue

Posted: Thu Dec 23, 2010 8:26 pm
by jzmwebdevelopment
My move_uploaded_file has the following vars

1. $_FILES[$sName]['tmp_name'] = ($_FILES["name"],
2. $newname = $_POST["ImageName"]);

Name is from the $_FILES array :)