3 回答

TA貢獻1876條經驗 獲得超7個贊
$pic_file1 = $this->input->post('pic_file');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = 1000;
//$config['encrypt_name'] = TRUE;
// $config['overwrite'] = FALSE;
$config['file_name'] = time();
$this->load->library('upload', $config);
$this->upload->initialize($config);
if ( ! $this->upload->do_upload('pic_file'))
{
$error = array('error' => $this->upload->display_errors());
print_r($error);
}
else
{
$data = array('upload_data' => $this->upload->data());
// print_r($data);
}

TA貢獻1111條經驗 獲得超0個贊
上面的代碼與任何框架相關。如果您是 php 新手,請嘗試使用下面提到的簡單代碼。
$target_dir = "/var/www/html/uploads/"; // this is base path
$imageFileType = strtolower(pathinfo(basename($_FILES["pic_file"]["name"]),PATHINFO_EXTENSION));
$filename = time().$imageFileType; //save this file name to database $filename
$target_file = $target_dir.$filename
if(isset($_POST["submit"])) {
$check = getimagesize($_FILES["pic_file"]["tmp_name"]);
if($check !== false) {
if (move_uploaded_file($_FILES["pic_file"]["tmp_name"], $target_file)) {
echo "The file ". basename( $_FILES["pic_file"]["name"]). " has been uploaded on : ".$target_file;
} else {
echo "Sorry, there was an error uploading your file.";
}
} else {
echo "File is not an image.";
}
}
如果您還需要 HTML,請告訴我我會提供。
- 3 回答
- 0 關注
- 191 瀏覽
添加回答
舉報