以下是我的代碼,用於上傳圖像並使用各自的圖像名稱更新數據庫。在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