-1

こんにちは私はサイトの実装にフレームワークcakephpを使用することを模索してきました。私の現在のPHPスクリプトでは、次のエラーが発生します。未定義のオフセット:1で、すでに頭痛の種になっています。私が間違っていることを助けてくれませんか。

私のコードはここにあります:

function file_upload($file_array, $id){
    if(count($file_array))
    {
        $location = "files/library-files/";

        foreach ($file_array as $file) {
            $ext = explode(".", $file['name']);
            $new_name = md5(uniqid());
            $target_path = $location . $new_name .".".$ext[1];
            if(move_uploaded_file($file['tmp_name'], $target_path))
            {
                $this->LibraryFiles->create();
                $this->LibraryFiles->set('id', $new_name);
                $this->LibraryFiles->set('library_id', $id);
                $this->LibraryFiles->set('name', $file['name']);
                $this->LibraryFiles->set('ext', $ext[1]);
                $this->LibraryFiles->set('type', $file['type']);
                $this->LibraryFiles->set('size', $file['size']);
                if($this->LibraryFiles->save())
                {

                }
                else
                {

                }
            }
        }
    }
}
4

2 に答える 2

2

次のチェックを追加できます。

if(isset($ext[1]))
{
    $target_path = $location . $new_name .".".$ext[1];
}
else if($file['name'] !== '.' && $file['name'] !== '..')
{
    $target_path = $location . $new_name;
}
else
{
    continue;
}
于 2012-10-18T07:51:01.720 に答える
-1

この$target_path=$locationを置き換えました。$new_name。"。"。$ext[1];

if (isset($target_path)) 
$target_path = $location . $new_name .".".$ext[1]; 
else 
$target_path = '';

そして今、私は幸せです:D

于 2012-10-18T08:58:01.707 に答える