0

複数の画像をアップロードできるようにするスクリプトをコーディングしようとしています。これは私が使用しているコードです。

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;
    }
}

誰かがこれを修正する方法についてのアイデアを持っていますか?

4

1 に答える 1

0

問題は次の行にあると思います。

$image->attach_file($_FILES['file']);

$_FILES だけでなく、 $_FILES['file'] を繰り返し処理しています

また、ループ内で反復している配列を呼び出しています

呼び出しは次のようになります

$image->attach_file($file);

これが役に立ちますように

于 2012-07-19T16:04:27.667 に答える