gpt4 book ai didi

php - 文件未使用 html 输入类型文件上传

转载 作者:行者123 更新时间:2023-12-05 01:19:45 25 4
gpt4 key购买 nike

我想使用 HTML 输入类型文件上传文件,但它不起作用。该文件未上传到预期的文件夹和数据库(我想将文件名存储到表中)。当我从浏览器检查时,它没有给我任何错误。当我单击“上传”按钮时,网址类似于 http://localhost/mywebsite/ajax/upload ? ,方法 GET,状态代码 200 OK。我做错了什么?

我正在使用 mac、xampp、phpmyadmin、chrome。

这是我的观点:

<form action="<?php echo site_url('admin/upload')?>" enctype="multipart/form-data">
<input type="file">
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-upload" aria-hidden="true" ></span> Upload
</button>
</form>

Controller :

function upload()
{
if (!empty($_FILES))
{
$filename = $_FILES["file"]["name"];
$file_basename = substr($filename, 0, strripos($filename, '.'));
$file_ext = substr($filename, strripos($filename, '.'));
$tempFile = $_FILES['file']['tmp_name'];
$data = "admin".uniqid().$file_ext;
$targetPath = getcwd() . '/kirim_undangan/';
$targetFile = $targetPath . $data ;
move_uploaded_file($tempFile, $targetFile);

$data_user = array(
'request_id' => $request_id,
'status' => '1',
'filename_admin' => $uploadedFileName,
);
$this->load->model('excel');
$this->excel->upload_excel($data_user);
}
}

模型:

function upload_excel($allDataInSheet,$request_id)
{
$regex = "~\d{5}~";
array_shift($allDataInSheet);
foreach ($allDataInSheet as $key)
{
preg_match($regex, $key['B'], $result);
$data = array(
'request_id' => $request_id,
'to_name' => $key['A'],
'to_phone' => $key['C'],
'to_address' => $key['B'],
'to_zipcode' => $result[0],
'tariff' => '0'
);
$this->db->insert('excel', $data);
$this->db->update('request',$request_id);
}
}

最佳答案

你必须在输入中添加一个名字

<form method="post" action="<?php echo site_url('admin/upload')?>" enctype="multipart/form-data">
<input type="file" name="file">
<button type="submit" class="btn btn-success"><span class="glyphicon glyphicon-upload" aria-hidden="true" ></span> Upload
</button>
</form>

关于php - 文件未使用 html 输入类型文件上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37670308/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com