CodeIgniter file upload validation of ppt and pptx files - php

$config = array(
'upload_path' => 'resources/lectures',
'allowed_types' => 'pdf|zip|doc|docx|ppt|pptx',
'remove_spaces' => TRUE,
'overwrite' => FALSE,
'max_size' => 0,
);
This is my config array for file upload, and all files are uploading fine except for ppt and pptx. I checked the error message using the display_errors() method, it said 'The filetype you are attempting to upload is not allowed'.

This is a bug of Codeigniter.
Open application/config/mime.php
and replace line no 33 (probably) with the following line:
'ppt' => array('application/powerpoint', 'application/vnd.ms-powerpoint', 'application/vnd.ms-office', 'application/msword'),
and add the following line to the array:
'pptx' => array('application/vnd.openxmlformats-officedocument.presentationml.presentation', 'application/zip', 'application/msword','application/vnd.ms-powerpoint'),

Related

Uploading files in codeigniter

A Problem was encountered while attempting to move the uploaded file to the final destination
Unable to upload the file in codeigniter using their upload class, upload directory is also exist,
below is a code
$config = array(
'upload_path' => './upload_dir/users_docs/',
'allowed_types' => 'gif|png|jpeg',
'max_size' => 0,
'max_width' => 0,
'max_height' => 0,
'file_name' => $this->currTime,
);
$this->load->library('upload', $config);
if (!empty($_FILES['company_logo']['name']) && !$this->upload->do_upload('company_logo')) {
$error = array('error' => $this->upload->display_errors());
$this->session->set_flashdata('error_message', $error['error']);
redirect('home');
}
$data = array('upload_data' => $this->upload->data());
There was an issue in the 'file_name' => $this->currTime, the format of time was not correct, Apostrophe where coming in the filename var, I just changed it to something else, now it's working, Thank you

Codeigniter AJAX file upload not working

I am trying to upload a file to the same directory in which application folder is present
-application
-images
-system
-others...
The code that I am trying is
$config = array(
'upload_path' => "images",
'allowed_types' => "*",
'overwrite' => TRUE,
'max_size' => "2048000", // Can be set to particular file size , here it is 2 MB(2048 Kb)
'max_height' => "768",
'max_width' => "1024",
);
if(isset($_FILES["image"]["name"])) {
if (0 < $_FILES['image']['error']) {
echo 'Error Occurred During Upload Of File ' . $_FILES['image']['error'];
} else {
$this->load->library('upload', $config);
if(!$this->upload->do_upload('image')) {
echo $this->upload->display_errors(); //ALWAYS THIS LINE IS EXECUTING
}
else {
echo "FILE UPLOADED";
}
}
} else {
echo "Please Select A File";
}
The problem is that always the line having comment inside innermost if is executing and it says <p>The upload path does not appear to be valid.</p>.
When I tried to check whether that directory exists using is_dir, it also says that directory exists and also I tried giving it 777 file permission but still I am getting the same errors. I also tried most of the similar answers online but none worked.
Please HELP
Try this:
$config = array(
'upload_path' => "./images/",
'allowed_types' => "*",
'overwrite' => TRUE,
'max_size' => "2048000",
'max_height' => "768",
'max_width' => "1024",
);

PHP Codeigniter uploads failed with no errors

I want to upload a file using a registration form. I used File_Upload library of Codeigniter. But the file does not upload to the destination and no errors appears.
This is just part of my code (All of them are really huge)
Controller (seeker_register.php):
public function submit(){
...
$this->load->model('mseeker_register');
$user_id = $this->mseeker_register->register($data);
View (vseeker_register.php):
$attr = array("class" => 'form-horizontal seeker_register','id' => 'form-seeker-register');
echo form_open_multipart('seeker_register/submit',$attr);
...
<div class="col-sm-6 col-sm-offset-3">
<input name="Aks" type="file" class="fileinput" accept=".jpg, .jpeg">
</div>
Model (mseeker_register.php):
...
// Prepare Aks
$config = array(
'upload_path' => './img/users',
'allowed_types' => 'jpg|jpeg|JPG|JPEG',
'max_size' => '200',
'max_width' => '1024',
'max_height' => '768');
$this->upload->initialize($config);
$this->upload->do_upload('Aks');
$this->upload->display_errors();
exit();
...
This is $this->upload->data() output:
Array
(
[file_name] => Clipboard-2.jpg
[file_type] => image/jpeg
[file_path] => D:/khayyamkar.ir/www/img/users/
[full_path] => D:/khayyamkar.ir/www/img/users/Clipboard-2.jpg
[raw_name] => Clipboard-2
[orig_name] =>
[client_name] => Clipboard-2.jpg
[file_ext] => .jpg
[file_size] => 156.42
[is_image] => 1
[image_width] =>
[image_height] =>
[image_type] =>
[image_size_str] =>
)
When I scanned your code I realized that you you don't have a way to view the error(s).
To view what the error(s) are/is you need to use var_dump() or print_r() php method to view what are the error(s).
for example:
var_dump($this->upload->display_errors());
in your current code you need to change :
$this->upload->display_errors();
exit();
TO:
var_dump($this->upload->display_errors());
exit();
You need to identify the error first to come up with a solution.
:)
public function register() {
$config = array(
'upload_path' => './img/user',
'allowed_types' => 'jpg|jpeg|JPG|JPEG|png',
'max_size' => '200',
'max_width' => '1024',
'max_height' => '768');
$this->upload->initialize($config);
// you need to make sure that the upload path is existing
// and also check the folder permission to be rwxr-xr-x
// if you installed in a server where permission is required
// for you to create image inside the folder
// create a folder img/user in the root directory of the project
// where application or system located
// this will check
if ($this->upload->do_upload('Aks')) {
echo 'success'; die;
} else {
var_dump($this->upload->display_errors());die;
}
}
see File Upload CodeIgniter

Cant Upload doc format files in codeigniter

$config['allowed_types'] = 'doc|Doc';
I want to upload Doc format file only but cant upload doc format file just written The filetype you are attempting to upload is not allowed.
Why?
How to solve issue,
I add mimes file,
'doc' => 'application/msword',
'docx' => array('application/vnd.openxmlformats-officedocument.wordprocessingml.document', 'application/zip'),
'xlsx' => array('application/vnd.openxmlformats-officedocument.spreadsheetml.sheet', 'application/zip'),
you can use this function
public function do_upload(){
$this->config = array(
'upload_path' => dirname($_SERVER["SCRIPT_FILENAME"])."/files/",
'upload_url' => base_url()."files/",
'allowed_types' => "gif|jpg|png|jpeg|pdf|doc|xml|docx|GIF|JPG|PNG|JPEG|PDF|DOC|XML|DOCX|xls|xlsx",
'overwrite' => TRUE,
'max_size' => "1000KB",
'max_height' => "768",
'max_width' => "1024"
);
$this->remove_dir($this->config["upload_path"], false);
$this->ci->load->library('upload', $this->config);
if($this->ci->upload->do_upload())
{
$this->ci->data['status']->message = "File Uploaded Successfully";
$this->ci->data['status']->success = TRUE;
$this->ci->data["uploaded_file"] = $this->ci->upload->data();
}
else
{
$this->ci->data['status']->message = $this->ci->upload->display_errors();
$this->ci->data['status']->success = FALSE;
}
}

jQuery-File-Upload not creating thumbnail file after uploading on server

I am using jQuery-File-Upload (basic version) to upload file on server using jQuery. My original image file is uploading successfully but it is not uploading the thumbnail file into thumbnail folder.
I also set the write permission on this folder. But same code on my localhost is working fine, after uploading on server it is not creating thumbnail.
jQuery.each(data.result.files, function (index, file) {
alert(file.thumbnailUrl);
This alert message is showing blank on server. but on localhost showing uploaded path perfectly.
My UploadHandler.php __construct() Code is :-
function __construct($options = null, $initialize = true, $error_messages = null) {
$this->options = array(
'script_url' => $this->get_full_url().'/',
'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'../../../../../../temp/',
'upload_url' => $this->get_full_url().'../../../../../../temp/',
'user_dirs' => false,
'mkdir_mode' => 0755,
'param_name' => 'files',
// Set the following option to 'POST', if your server does not support
// DELETE requests. This is a parameter sent to the client:
'delete_type' => 'DELETE',
'access_control_allow_origin' => '*',
'access_control_allow_credentials' => false,
'access_control_allow_methods' => array(
'OPTIONS',
'HEAD',
'GET',
'POST',
'PUT',
'PATCH',
'DELETE'
),
'access_control_allow_headers' => array(
'Content-Type',
'Content-Range',
'Content-Disposition'
),
// Enable to provide file downloads via GET requests to the PHP script:
// 1. Set to 1 to download files via readfile method through PHP
// 2. Set to 2 to send a X-Sendfile header for lighttpd/Apache
// 3. Set to 3 to send a X-Accel-Redirect header for nginx
// If set to 2 or 3, adjust the upload_url option to the base path of
// the redirect parameter, e.g. '/files/'.
'download_via_php' => false,
// Read files in chunks to avoid memory limits when download_via_php
// is enabled, set to 0 to disable chunked reading of files:
'readfile_chunk_size' => 10 * 1024 * 1024, // 10 MiB
// Defines which files can be displayed inline when downloaded:
'inline_file_types' => '/\.(gif|jpe?g|png)$/i',
// Defines which files (based on their names) are accepted for upload:
'accept_file_types' => '/.+$/i',
// The php.ini settings upload_max_filesize and post_max_size
// take precedence over the following max_file_size setting:
'max_file_size' => null,
'min_file_size' => 1,
// The maximum number of files for the upload directory:
'max_number_of_files' => null,
// Image resolution restrictions:
'max_width' => null,
'max_height' => null,
'min_width' => 1,
'min_height' => 1,
// Set the following option to false to enable resumable uploads:
'discard_aborted_uploads' => true,
// Set to false to disable rotating images based on EXIF meta data:
'orient_image' => true,
'image_versions' => array(
// Uncomment the following version to restrict the size of
// uploaded images:
/*
'' => array(
'max_width' => 1920,
'max_height' => 1200,
'jpeg_quality' => 95
),
*/
// Uncomment the following to create medium sized images:
'medium' => array(
'max_width' => 400,
'max_height' => 400,
'jpeg_quality' => 80
),
'thumbnail' => array(
// Uncomment the following to use a defined directory for the thumbnails
// instead of a subdirectory based on the version identifier.
// Make sure that this directory doesn't allow execution of files if you
// don't pose any restrictions on the type of uploaded files, e.g. by
// copying the .htaccess file from the files directory for Apache:
//'upload_dir' => dirname($this->get_server_var('SCRIPT_FILENAME')).'../../../../../../thumbnail/',
//'upload_url' => $this->get_full_url().'../../../../../../thumbnail/',
// Uncomment the following to force the max
// dimensions and e.g. create square thumbnails:
//'crop' => true,
'max_width' => 80,
'max_height' => 80
)
)
);
if ($options) {
$this->options = array_merge($this->options, $options);
}
if ($error_messages) {
$this->error_messages = array_merge($this->error_messages, $error_messages);
}
if ($initialize) {
$this->initialize();
}
}

Categories