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 关注
- 151 浏览
添加回答
举报