ファイルのアップロードを許可するフォームがあります。データベースには問題なく追加されますが、指定したフォルダーにファイルが保存されません。私のビューとモデル コードは以下のとおりです (私のコントローラーは、ファイルが設定されているかどうかを確認してからアップロードに進みます)
意見:
<form action="admin/admin_area/save_personnel" method="post" enctype="multipart/form-data" id="add_personnel">
<input type="file" name="offshore_medical_certificate" />
</form>
コントローラ:
function uploadOffshoreMedical($uid)
{
$status = "";
$msg = "";
$file_element_name = 'offshore_medical_certificate';
$certificate_name = 'Offshore Medical';
if ($status != "error")
{
$config['upload_path'] = './certificate_files/';
$config['allowed_types'] = 'pdf|doc|docx|txt|png|gif|jpg|jpeg|';
$config['max_size'] = 1024 * 8;
$config['encrypt_name'] = TRUE;
$this->load->library('upload', $config);
if (!$this->upload->do_upload($file_element_name))
{
$status = 'error';
$msg = $this->upload->display_errors();
}
else
{
$data = $this->upload->data();
$file_id = $this->saveCertificate($uid, $data['raw_name'], $data['file_ext'], $certificate_name);
}
if($file_id)
{
$status = "success";
$msg = "File successfully uploaded";
}
else
{
unlink($data['full_path']);
$status = "error";
$msg = "Something went wrong when saving the file, please try again.";
}
@unlink($_FILES[$file_element_name]);
}
echo json_encode(array('status' => $status, 'msg' => $msg));
}
フォームから正しいファイル名を取得しました。アップロードしているファイルは、正しいサイズと正しいファイル拡張子です。私はローカルホストから作業しているので、フォルダーのアクセス許可は問題ありませんが、何らかの理由で機能していません。最近、別のプロジェクトで同様のことを行いましたが、問題が見つからないようです。
どんな助けでも大歓迎です。
編集:
$data を印刷すると、次のようになります
Array ( [file_name] => 08f8ce288e45207735bdb3f0c3139a0a.txt [file_type] => text/plain [file_path] => C:/wamp/www/marine/certificate_files/ [full_path] => C:/wamp/www/marine/files/08f8ce288e45207735bdb3f0c3139a0a.txt [raw_name] => 08f8ce288e45207735bdb3f0c3139a0a [orig_name] => license.txt [client_name] => license.txt [file_ext] => .txt [file_size] => 2.44 [is_image] => [image_width] => [image_height] => [image_type] => [image_size_str] => )
{"status":"error","msg":"Something went wrong when saving the file, please try again."}