以下是我的代码,用于上传图像并使用各自的图像名称更新数据库。在MySQL数据库中PHP文件上传和更新相同
上传工作正常,但在语法上有一些问题来更新mysql数据库。
function storeimage()
{
$files = array();
$target_path1 = $_FILES['file1']['tmp_name'];
$target_path2 = $_FILES['file2']['tmp_name'];
$target_path3 = $_FILES['file3']['tmp_name'];
$files = array(1=>'file1',2=>'file2',3=>'file3');
//uploadimages($files)
//$target_path = "images/";
foreach($files as $data)
{
$target_path = $_FILES[$data]['name'];
if(move_uploaded_file($_FILES[$data]['tmp_name'], "images/".$target_path))
{
$publish = $_POST['publish'];
$databaseupdate = "INSERT INTO `uploadfiles`.`uploads`
(`id`, `name1`, `name2`, `name3`, `publish`)
VALUES (NULL, '$files['file1']','$files['file2']','$files['file3']','$publish')";
$mysqlupdate = mysql_query($databaseupdate);
echo "The file ". basename($_FILES[$data]['name']).
" has been uploaded<BR>";
}
else
{
echo "There was an error uploading the file, please try again!";
}
$target_path ="";
}
}
请不要在全部大写中写出标题。 – 2011-12-21 20:48:18
我不认为内联替换适用于数组。尝试使用''“。$ files ['file1']。”''' – Corubba 2011-12-21 20:50:19
什么是“但在语法上有一些问题来更新mysql数据库”?你是否得到了错误,他们是什么?或者你只是不喜欢它,并希望其他人重写? – Robert 2011-12-21 20:50:39