[英]Codeigniter not uploading image files in png format
Codeigniter 3.1.6是我正在使用的版本。 當我嘗試以jpg格式上傳文件時成功,但是以png格式上傳文件不起作用,這是我的代碼。 我正在使用dropzone.js進行文件上傳
查看
<form action="admin/addimg" enctype="multipart/form-data" class="dropzone" style="margin-bottom: 5%; border: 2px dashed #0087F7; border-radius: 5px; background: white;" id="imgupld"></form>
<script>
Dropzone.options.imgupld = {
paramName: "file",
maxFilesize: 20, // MB
acceptedFiles: "image/*", // Accept images only
dictDefaultMessage: "Drag your image here"
};
</script>
調節器
function addimg()
{
if (!empty($_FILES))
{
$tempFile = $_FILES['file']['tmp_name'];
$targetPath = './assets/img/';
$targetFile = $targetPath . $_FILES['file']['name'];
move_uploaded_file($tempFile, $targetFile);
}
}
使用CI上傳庫可以很容易地做到這一點。首先,您需要在config-> autoload.php中加載庫
$autoload['libraries'] = array('upload');
或在您的控制器中。
class ImageUpload extends CI_Controller
{
public function Upload()
{
if($_FILES["uploadImage"]["error"]==4)//check if user select input any image to upload
{
$config['Upload_Path']='';//File upload path
$config['allowed_types']='jpeg|jpg|png';//set the preferred file formats here
$config['max_size']=100000;// Max File Size
if($this->upload->do_upload('uploadImage'))//uploading the data
{
$uploadData=$this->upload->data();//get the details of uploaded data
}else
{
$error=$this->upload->display_errors();//this return the error message if any error thrown
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.