.blend/.blender file upload using codeigniter - ajax

I want to upload .blend or .blender file using codeigniter...
$config['allowed_types'] = 'gif|jpg|jpeg|png|psd|xls|xlsx|xml|doc|docx|csv|mpeg|mpg|mp3|mpga|pdf';
$config['max_size'] = '5024';
$this->load->library('upload', $config);
$this->upload->initialize($config);
if (!$this->upload->do_upload($field)) {
echo 'error';
}else{
print_r($this->upload->data());
}
Which Mimes type i m used for blender file extension...

Related

How to remove existing file when uploading new one in codeigniter file uploading?

I am using codeigniter file uploading class to upload files and images in my local folder.I am using the code below, it's working fine.
public function do_upload() {
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|jpeg|pdf|txt|sql';
$config['max_size'] = 8048000;
$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('Emp_details_view', $error);
}
else {
$data = array('upload_data' => $this->upload->data());
$this->load->view('upload_success', $data);
}
}
Now, my question is how to remove previously added file when uploading new one.
You can use unlink() function to delete your previous image
unlink('image-path/image-name');
first save your filename in a database table then when unlinking take that value from database and unlink. here uploads is the foldername .
unlink("uploads/".$val['image']);
$val['image'] contains imagename from db.

how to get upload file name in codeigniter

Hi i'm trying to upload image to a folder and image name in database
in view
echo form_open_multipart('subscribers_c/actioncreate',array('class'=>'form'));`enter code here`
<input type='file' name='img'>
in controller
$config['upload_path'] ='./assets/uploads/subscribers_photos'; //The path where the image will be save
$config['allowed_types'] = 'gif|jpg|png'; //Images extensions accepted
$config['max_size'] = '2048';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$config['overwrite'] = TRUE;
$this->load->library('upload', $config); //Load the upload CI library
if (!$this->upload->do_upload('img'))
{
$uploadError = array('upload_error' => $this->upload->display_errors());
//$this->set_flashdata('msg_error', $uploadError, site_url().'/subscribers_c/actioncreate');
}
$file_info = $this->upload->data('img');
$img_name = $file_info['file_name'];
$data=array(
'chit_fund_id'=>$this->input->post('cid'),
'first_name'=>$this->input->post('fname'),
'last_name'=>$this->input->post('lname'),
'dob'=>$this->input->post('bd'),
'gender'=>$this->input->post('g'),
'contact_number'=>$this->input->post('mob'),
'address'=>$this->input->post('add'),
'email_id'=>$this->input->post('eml'),
'bid_status'=>$this->input->post('b_status'),
'user_status'=>$this->input->post('u_status'),
'image_name'=>$img_name,
);
//print_r($data);
image_name is not having any value
how to get image name .
Instead of img in upload data
$file_info = $this->upload->data('img');
Try
$file_info = $this->upload->data();
$img = $file_info['file_name'];
And on here $config['upload_path'] = './assets/uploads/subscribers_photos'; end with /
Like $config['upload_path'] = './assets/uploads/subscribers_photos/';
Inside the view call the form_upload function(if needed, your one is also correct):
<?php echo form_upload('pic'); ?>
Inside controller function for upload:
$img_name = $_FILES["pic"]["name"];
By using this code you will get the file name.
$img_name = $this->upload->data('file_name');

file upload code igniter..not working

This is in my controller for file upload
$config['upload_path'] = './assets/images/b2b/banner-agent/';
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite'] = TRUE;
$config['file_name'] = "$banner2";
$this->load->library('upload', $config);
$this->upload->data();
$this->upload->do_upload();
$this->upload->initialize($config);
is there any wrong with my code? The upload not working.
You can not simply call do_upload method before initializing and setting config variables for the upload class.
You need to modify your code like this:
$config['upload_path'] = './assets/images/b2b/banner-agent/';
$config['allowed_types'] = 'gif|jpg|png';
$config['overwrite'] = TRUE;
$config['file_name'] = $banner2;
$this->load->library('upload'); //initialize
$this->upload->initialize($config); //Alternately you can set preferences by calling the initialize function. Useful if you auto-load the class
$this->upload->do_upload(); // do upload
if($this->upload->do_upload()){
$this->upload->data(); //returns an array containing all of the data related to the file you uploaded.
}
You can consult Codeigniter wiki for that too:
http://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html
Hope this helps.

CodeIgniter - upload multiple text entries and files from single form

I have a single form on a page. It has 5 text fields and 3 upload file fields. I need to write the text and file paths to a database. I have seen many examples online but most are to upload a single file or to upload multiple files from the same upload field.
I am new to CodeIgniter so code snippets would be very helpful.
Many thanks in advance.
Another suggestion would be:
function upload()
{
$config['upload_path'] = $path; //$path=any path you want to save the file to...
$config['allowed_types'] = 'gif|jpg|png|jpeg'; //this is the file types allowed
$config['max_size'] = '1024'; //max file size
$config['max_width'] = '1024';//if file type is image
$config['max_height'] = '768';//if file type is image
$this->load->library('upload', $config);
foreach($_FILES as $Key => $File)
{
if($File['size'] > 0)
{
if($this->upload->do_upload($Key))
{
$data = $this->upload->data();
echo $data['file_name'];
}
else
{
// throw error
echo $this->upload->display_errors();
}
}
}
}
This will automatically work for ALL file inputs you post and it doesn't care about the name or quantity :)
HOpe this helps
$config['upload_path'] = $path; //$path=any path you want to save the file to...
$config['allowed_types'] = 'gif|jpg|png|jpeg'; //this is the file types allowed
$config['max_size'] = '1024'; //max file size
$config['max_width'] = '1024';//if file type is image
$config['max_height'] = '768';//if file type is image
//etc config for file properties, you can check all of them out on website
now suppose you have 3 files, which you want to save as 1.jpg, 2.jpg,3.gif, which are uploaded through 3 input fields, pic1, pic2, pic3 here is what you do
for($ite=1;$ite<=3;$ite++){
if(!empty($_FILES["pic".$ite]["name"])){ //if file is present
$ext = pathinfo($_FILES['pic'.$ite]['name'], PATHINFO_EXTENSION); //get extension of file
$config["file_name"]="$ite.$ext"; //rename file to 1.jpg,2.jpg or 3.jpg, depending on file number and its extension
$this->upload->initialize($config); //upload library of codeigniter initialize function with config properties set earlier
if(!$this->upload->do_upload("pic".$ite)){
//error code
}
}
}

image upload with codeigniter

Am having difficulties uploading images with codeigniter it keeps saying that i didn't select a file to upload.
this is my code
function do_upload()
{
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = '3000';
$config['max_width'] = '1024';
$config['max_height'] = '768';
$this->load->library('upload', $config);
if (!$this->upload->do_upload()){
echo $this->upload->display_errors();
}else{
echo $this->upload->data();
}
}
it doesn't even send the image to the directory.
try this function instead :
function upload_done() {
$config['overwrite'] = TRUE;
$config['encrypt_name'] = FALSE;
$config['remove_spaces'] = TRUE;
$config['upload_path'] = '/var/www/uploadfiles/'; // use an absolute path
$config['allowed_types'] = 'jpg|png';
$config['max_size'] = '0';
if ( ! is_dir($config['upload_path']) ) die("THE UPLOAD DIRECTORY DOES NOT EXIST");
$this->load->library('upload',$config);
if ( ! $this->upload->do_upload() )
{
echo "UPLOAD ERROR ! ".$this->upload->display_errors();
} else {
echo "THE IMAGE HAS BEEN UPLOADED : "; var_dump( $this->upload->data() );
}
}
Make sure your html looks like below.
<input type="file" name="userfile" size="20" />
Codeigniter's upload library assumes the name to be "userfile"
You need to change the call to do_upload() depending on the name you have given the form input. Lets say you have this code in your HTML:
<input type="file" name="image" />
You need to change:
$this->upload->do_upload()
to
$this->upload->do_upload('image')
By default CodeIgniter assumes the name is "userfile".

Resources