Hey,
I have the following code which inserts filenames from an array of input images into a database AND also upload the images onto the server…
public function saveImageNamesFromIdeasPage(){
$query = "SELECT MAX(ID) as max FROM ideas";
$result = mysql_query($query);
$max = mysql_fetch_array($result);
$ideasID = $max['max'];
$root = $_SERVER['DOCUMENT_ROOT']. "/kidsintranet/public_html/ideasfiles/";
foreach($_FILES['image']['name'] as $image){
if($image != ''):
$target_path = $root . basename($image);
move_uploaded_file($_FILES['image']['tmp_name'], $target_path);
endif;
$sql = "INSERT INTO ideas_files
(ideasID, ideas_files, deleted)
VALUES (
".$ideasID.",
'".$image."',
0
)";
$result = mysql_query($sql);
}
}
The INSERT works perfectly, so if for example there are 10 images, ALL the filenames are successfully inserted. A typical input file is as so:
<input type=“file” name=“image” id=“image1”/>
<input type=“file” name=“image” id=“image2”/>
<input type=“file” name=“image” id=“image3”/>
<input type=“file” name=“image” id=“image4”/>
…
…
…
<input type=“file” name=“image” id=“image10”/>
And so on…
But the images are not being uploaded? I get this error:
Notice: Array to string conversion in /public_html/kidsintranet/application/model/db/Ideas.class.php on line 112
Which is referring to this line:
move_uploaded_file($_FILES[‘image’][‘tmp_name’], $target_path);
Any ideas what the problem is?
Thanks