我試圖編碼一個腳本,使其可以上傳多個圖像。這是我正在使用的代碼。PHP多上傳圖片問題
if(isset($_POST['submit_images'])) {
$i = 0;
foreach($_FILES['file'] as $file) {
$image = new Image();
$image->member_id = $_POST['id'][$i];
$image->image_type = "MedlemsBillede";
$image->attach_file($_FILES['file']);
if($image->save()) {
$message = 'Billedet blev uploadet med succes.';
} else {
$message = join("<br />", $image->errors);
}
$i++;
}
}
我的問題就出在這調用函數:
$image->attach_file($_FILES['file']);
而且該功能看起來像這樣:
public function attach_file($file) {
if(!$file || empty($file) || !is_array($file)) {
$this->errors[] = "Der blev ikke uploadet nogen fil.";
return false;
} elseif($file['error'] != 0) {
$this->errors[] = $this->upload_errors[$file['error']];
return false;
} else {
$this->temp_path = $file['tmp_name'];
$this->file_name = str_replace(' ', '_', basename($file['name']));
$this->file_type = $file['type'];
$this->file_size = $file['size'];
$this->ts = date('Y-m-d H:i:s');
return true;
}
}
是否有人對如何解決這一問題的想法?
*我的問題在於這個函數的調用* ...有什麼問題?任何錯誤?它執行時會發生什麼? – ManseUK 2012-07-19 15:54:21
我無法發送到通過attach_file函數更正數組的一部分。當我僅使用該功能上傳一個文件時,它工作正常。 – nickifrandsen 2012-07-19 16:00:11