I got
Array
(
)
1$_FILES:
ImagePath:
Should I access it by going ['imagePath']['name']?
Upload Function Issue
Moderator: General Moderators
-
jzmwebdevelopment
- Forum Commoner
- Posts: 32
- Joined: Mon Nov 01, 2010 1:45 pm
Re: Upload Function Issue
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:and then out of that array, get out the 'name' item:
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.
Code: Select all
$tempImagePathArray = $_FILES['ImagePath'];Code: Select all
$name = $tempImagePathArray['name'];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.
Last edited by ccsdg on Thu Dec 23, 2010 2:27 pm, edited 1 time in total.
-
jzmwebdevelopment
- Forum Commoner
- Posts: 32
- Joined: Mon Nov 01, 2010 1:45 pm
Re: Upload Function Issue
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?
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
1. The $_FILES array will be empty if you have not uploaded a file. Remember you had this: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.
Code: Select all
Array
(
[ImagePath] => Array
(
[name] => Corn.jpg
[type] => image/jpeg
[tmp_name] => /tmp/phpz8Emls
[error] => 0
[size] => 72068
)
)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.
-
jzmwebdevelopment
- Forum Commoner
- Posts: 32
- Joined: Mon Nov 01, 2010 1:45 pm
Re: Upload Function Issue
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
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
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
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
-
jzmwebdevelopment
- Forum Commoner
- Posts: 32
- Joined: Mon Nov 01, 2010 1:45 pm
Re: Upload Function Issue
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
1. $_FILES[$sName]['tmp_name'] = ($_FILES["name"],
2. $newname = $_POST["ImageName"]);
Name is from the $_FILES array