我正在使用codeigniter 3,在3210函數中得到如You did not select a file to upload.
的錯誤,但正常的php函數move_uploaded_file()
正常工作。我提到了大多數來自stackoverflow的答案,但我沒有得到解決方案。Codeigniter文件上傳錯誤:'您沒有選擇要上傳的文件'
我認爲這可能在wamp
問題,但我沒有弄清楚它在哪裏。 如果這段代碼在你的機器上工作,那麼它將在我的wamp php或Apache設置中出現。
查看:(upload.php的)
<!DOCTYPE HTML>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>
<?php echo form_open_multipart('welcome/do_upload'); ?>
<input id="sfile" type="file" name="file">
<input type="submit" value="Submit">
<?php echo form_close(); ?>
</body>
</html>
控制器:(的welcome.php)
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if (! $this->upload->do_upload()) //not working
{
$error = array('error' => $this->upload->display_errors());
var_dump($error);
}
else
{
$data = array('upload_data' => $this->upload->data());
}
echo $basename = $_FILES['file']['name'];
move_uploaded_file($_FILES['file']['tmp_name'],$config['upload_path'].$basename);
// move_uploaded_file() works fine
}
嘗試在'$這個 - > upload-> do_upload(「文件」)',並檢查 – Saty
@Saty是的,我嘗試過同樣的問題 – 151291
檢查文件的大小你,因爲你設置上傳'$通過字段名config ['max_size'] ='100';'。這意味着你不能喲上傳文件大小超過100 kb – Saty