this is a code for swf fiel uploading but the problem is it works fine on localhost but not in the remote server.here is my controller
function do_upload()
{
$pid=$this->input->post('Page_id');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'swf';
$config['max_size'] = '1048';
$config['file_name'] =$pid;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
}
else{
$data=array(
'id'=>$pid,
'link'=>base_url()."uploads/",
'file_name'=>$config['file_name']
);
$this->file_upload_model->upload_data($data);
$this->upload_success();
}
}
i have not done anything except just uploading the path and file name to the database in model. see the demo here
Try this
$pid=$this->input->post('Page_id');
$config['file_name'] = $pid;
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'swf';
$config['max_size'] = '1048';
$config['remove_spaces'] = TRUE;
$this->load->library('upload', $config);
if ($this->upload->do_upload())
{
//upload successful
//do something
}
else
{
$this->session->set_flashdata('error',$this->upload->display_errors());
redirect('controller/method');
/*
In the view file you can echo the error like this
echo $this->session->flashdata('error');
*/
}
You have pass the the field name in the do_upload call like this:
$config = array(
'allowed_types' => 'jpg|jpeg|swf |png', // pipe seperated file types
'upload_path' => './uploads/', // should be the root path
'max_size' => '1048',
'file_name' => $pid
);
$this->load->library('upload', $config);
if (!$this->upload->do_upload('your_field_name')) {
// like $this->upload->do_upload($pid)
$error = array('error' => $this->upload->display_errors());
} else {
$swf_data = $this->upload->data();
}
Hope it makes sense
it may be due to PHP server version and it's option.
1).go to cpanel account
2).click "select php version", in the software section.
3).tap the "fileinfo" chexbox in the php option and save.
now you can upload file perfectly.
Related
I wish to upload a file to folder and then save its path in database, but i got stuck in first step only
whenever i am trying to upload a file i am getting a message
You did not select a file to upload
the code that i used is
view
<?php
echo form_open_multipart('recruiter/adddata);
$data = array(
'type'=>'file',
'name'=>'userfile',
'class'=>'fileinput btn-info',
'id'=>'filename3',
'data-filename-placement'=>'inside',
'title'=>'Resume'
);
echo form_upload($data);
$data = array(
'type'=>'submit',
'class'=>'btn btn-danger',
'name'=>'submit',
'content'=>'Submit'
);
echo form_button($data);
echo form_close();
?>
Controller
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'doc|docx|pdf';
$config['max_size'] = 10000;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
print_r($error); //only for checking purposes
}
else
{
$data = array('upload_data' => $this->upload->data());
print_r($data); //only for checking purposes
}
Can anyone please tell how can i upload the file and save its path in database
Make some changes like:
echo form_upload($data);
to
<?php echo form_open_multipart();?>
Controller function part:
//start of file upload code
$config['upload_path'] = './uploads/';
$config['allowed_types'] = '*';
$this->load->library('upload', $config);
$this->upload->do_upload();
$data = $this->upload->data();
//end of file upload code
I don't know how to set the allowed_types, and the markdown file suffix is .md. It always says:
The filetype you are attempting to upload is not allowed.
English is not my native language, so I hope this makes sense. My code:
public function do_upload()
{
$config['upload_path'] = './blog/';
$config['allowed_types'] = ''; //file's tye
$config['max_size'] = 50;
$config['max_width'] = 1024;
$config['max_height'] = 768;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload('userfile'))
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('houtai_view', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
//$this->load->view('upload_success', $data);
}
}
You just need to allowed_types in your $config array
$config['allowed_types'] = 'md';
If you want to allow all kinds of files than you can use * like:
$config['allowed_types'] = '*';
File Uploading Class
**Customize File type allow **
$config['allowed_types'] = 'gif|jpg|png';
You can edit APPATH.'config/mimes.php' file and add 'md' => 'text/plain', to array.
I am uploading file in codeigniter using
$this->upload->do_upload('image')
but when file moves to particular path the file extension is changed (it's changed to lower case)
for example if I upload file "profile.JPG" it's changes to "profile.jpg"
please change CI system library
default in CI upload library $file_ext_tolower = FALSE.
.system\libraries\upload.php
public $file_ext_tolower = TRUE;
do_upload does this
$config['allowed_types'] = 'gif|jpg|png'
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png';
$config['max_size'] = '100';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('upload_form', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
If you want to use same name / extension you send to save your file. You can use :
$upload_dir= $this->config->item("upload_dir");
$fileName = $_POST['sku_code'].".".$extension;
$filePath = $upload_dir.$fileName;
move_uploaded_file($_FILES["image-file"]["tmp_name"],$filePath );
Useful link :
https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html
I'm setting up an upload form in CodeIgniter. I've setup the allowed_types parameter to:
$config['allowed_types'] = 'xls|xlsx';
And added the following line to config/mimes.php:
'xls' => array('application/excel', 'application/vnd.ms-excel', 'application/msexcel'),
'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
However, despite the file I'm trying to upload being an xlsx file CI is still telling me the filetype isn't allowed. Any thoughts?
public function do_upload() {
// Change this if you change the upload directory
$upload_path = "/webusers/ad6vcf/public_html/funding_manager/application/uploads";
$config['upload_path'] = $upload_path;
//At some point will add support for csv
$config['allowed_types'] = 'xls|xlsx';
//Max 5000kb please
$config['max_size'] = '5000';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->upload($error);
} else {
$upload_data = $this->upload->data();
bulk_insert($upload_path . $upload_data['file_name']);
}
}
Please try this
$this->load->library('upload', $config);
$this->upload->initialize($config);
Have you tried this?
if (!$this->upload->do_upload('put the name of the input field here'))
Other file listed is uploading fine, but swf file is not uploading and giving a error of file type is not supported.
Here is my controller
function do_upload(){
$pid=$this->input->post('Page_id');
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'swf|png|gif|jpg';
$config['max_size'] = '1048';
$config['file_name'] =$pid;
$this->load->library('upload', $config);
if ( ! $this->upload->do_upload())
{
$error = array('error' => $this->upload->display_errors());
$this->load->view('admin/upload', $error);
}
else
{
$data = array('upload_data' => $this->upload->data());
$this->upload_success();
}
}
might be a bug with the File Upload Class in the _file_mime_type function
look for more here
You haven't pass the the field name in the do_upload call like
$config = array(
'allowed_types' => 'jpg|jpeg|swf|png', // pipe seperated file types
'upload_path' => './uploads/',// should be the root path
'max_size' => '1048',
'file_name' =>$pid
);
$this->load->library('upload', $config );
if (!$this->upload->do_upload('your_field_name')){
// like $this->upload->do_upload($pid)
$error = array('error' => $this->upload->display_errors());
}else{
$swf_data = $this->upload->data();
}
Hope it makes sense