Codeigniter 不上传 png 格式的图像文件
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 上传轻松完成 library.First 您需要在 config->autoload.php
中加载库
$autoload['libraries'] = array('upload');
或在您的 controller.Example
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
}
}
}
}
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 上传轻松完成 library.First 您需要在 config->autoload.php
中加载库 $autoload['libraries'] = array('upload');
或在您的 controller.Example
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
}
}
}
}