Ok, first I need to set the record straight: I am no expert in PHP... This is me trying to get my head around some weird error.
Basically the set up is:
-A form with various inputs (text, textarea and file) via GET method
-A javascript script to add multiple file upload elements
-a php file that executes to add everything to the DB.
To make it slightly more complex, the form is generated within a php tag because it fetches data from the DB. I dont think this is where the problem lies, but as I said, no expert...
Now the GET method works, with all the text and textarea elements. The PHP script goes perfectly with DB connectivity until it reaches the %_FILES variable. It states "undefined index: images...".
"images" is the index of the file input element (obviously), but it doesnt want to recognize it at all.
If I add:
I get an empty array, but if I add
The filename from the upload(s) are clearly visible in the array with the other values from the other elements. My small amount of PHP knowledge is telling me this is where the problem is, and it shouldnt be in the $_GET array?
Heres a basic snippet of the PHP code within the webpage:
The "add_product.php" file:
The index of the file element is "images[]" because of the multiple file uploads (use this source, but even changing it to a single upload doesnt help.
Oh, and the reason I have a javascript for the element adding is because I dont have a fixed number of uploads.
Hope this makes sense and someone can help sort it out...
Thanks,
Sysem
Basically the set up is:
-A form with various inputs (text, textarea and file) via GET method
-A javascript script to add multiple file upload elements
-a php file that executes to add everything to the DB.
To make it slightly more complex, the form is generated within a php tag because it fetches data from the DB. I dont think this is where the problem lies, but as I said, no expert...
Now the GET method works, with all the text and textarea elements. The PHP script goes perfectly with DB connectivity until it reaches the %_FILES variable. It states "undefined index: images...".
"images" is the index of the file input element (obviously), but it doesnt want to recognize it at all.
If I add:
Code:
print_r($_FILES)
I get an empty array, but if I add
Code:
print_r($_GET)
The filename from the upload(s) are clearly visible in the array with the other values from the other elements. My small amount of PHP knowledge is telling me this is where the problem is, and it shouldnt be in the $_GET array?
Heres a basic snippet of the PHP code within the webpage:
Code:
echo
'<div>
[INDENT]<form action="add_product.php" method="get" entype="multipart/form-data">
[INDENT]<fieldset>
[INDENT]<input type="text" name="name" />
<input type="file" name="images[]" />[/INDENT]
</fieldset>[/INDENT]
</form> [/INDENT]
</div>'
The "add_product.php" file:
Code:
for each ($_FILES["images"]["error"] as $key => $error) {
[INDENT]if ($error == UPLOAD_ERR_OK) {
[INDENT]$tmp_name $_FILES["images"]["tmp_name"][$key];
$name = $_FILES["images"]["name"][$key]'
move_upload_file($tmp_name, "images/uploads/$name");[/INDENT]
}[/INDENT]
}
The index of the file element is "images[]" because of the multiple file uploads (use this source, but even changing it to a single upload doesnt help.
Oh, and the reason I have a javascript for the element adding is because I dont have a fixed number of uploads.
Hope this makes sense and someone can help sort it out...
Thanks,
Sysem