Codeigniter obtain image name for multiple files
I have some code that i am using to upload multiple images i a form. I am uploading and renaming the images like this
//Obtain Picture
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 5000;
$config['max_width'] = 2000;
$config['max_height'] = 2000;
$rand_name = 'vehicles'.rand(321,8999).'_'.time();
$config['file_name'] = $rand_name;
$this->load->library('upload', $config);
$this->upload->do_upload('logbook');
$this->upload->do_upload('inrep');
$this->upload->do_upload('insurance');
$this->upload->do_upload('vp');
$data = array('upload_data' => $this->upload->data());
the form names for the multiple uploads which are unrelated are as follows logbook,inrep,insurance and vp
The code above uploads the files and renames them but i would like to obtain the new names of the files given the form name of the fields.
Right now, the files are uploaded and renamed but i cant they are from which field name.
php codeigniter
add a comment |
I have some code that i am using to upload multiple images i a form. I am uploading and renaming the images like this
//Obtain Picture
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 5000;
$config['max_width'] = 2000;
$config['max_height'] = 2000;
$rand_name = 'vehicles'.rand(321,8999).'_'.time();
$config['file_name'] = $rand_name;
$this->load->library('upload', $config);
$this->upload->do_upload('logbook');
$this->upload->do_upload('inrep');
$this->upload->do_upload('insurance');
$this->upload->do_upload('vp');
$data = array('upload_data' => $this->upload->data());
the form names for the multiple uploads which are unrelated are as follows logbook,inrep,insurance and vp
The code above uploads the files and renames them but i would like to obtain the new names of the files given the form name of the fields.
Right now, the files are uploaded and renamed but i cant they are from which field name.
php codeigniter
Why you are not using loop to upload multiple images?
– Danish Ali
Jan 18 at 12:55
forms fields are unrelated.
– Gandalf
Jan 18 at 12:58
add a comment |
I have some code that i am using to upload multiple images i a form. I am uploading and renaming the images like this
//Obtain Picture
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 5000;
$config['max_width'] = 2000;
$config['max_height'] = 2000;
$rand_name = 'vehicles'.rand(321,8999).'_'.time();
$config['file_name'] = $rand_name;
$this->load->library('upload', $config);
$this->upload->do_upload('logbook');
$this->upload->do_upload('inrep');
$this->upload->do_upload('insurance');
$this->upload->do_upload('vp');
$data = array('upload_data' => $this->upload->data());
the form names for the multiple uploads which are unrelated are as follows logbook,inrep,insurance and vp
The code above uploads the files and renames them but i would like to obtain the new names of the files given the form name of the fields.
Right now, the files are uploaded and renamed but i cant they are from which field name.
php codeigniter
I have some code that i am using to upload multiple images i a form. I am uploading and renaming the images like this
//Obtain Picture
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 5000;
$config['max_width'] = 2000;
$config['max_height'] = 2000;
$rand_name = 'vehicles'.rand(321,8999).'_'.time();
$config['file_name'] = $rand_name;
$this->load->library('upload', $config);
$this->upload->do_upload('logbook');
$this->upload->do_upload('inrep');
$this->upload->do_upload('insurance');
$this->upload->do_upload('vp');
$data = array('upload_data' => $this->upload->data());
the form names for the multiple uploads which are unrelated are as follows logbook,inrep,insurance and vp
The code above uploads the files and renames them but i would like to obtain the new names of the files given the form name of the fields.
Right now, the files are uploaded and renamed but i cant they are from which field name.
php codeigniter
php codeigniter
asked Jan 18 at 12:51
GandalfGandalf
5,4892269121
5,4892269121
Why you are not using loop to upload multiple images?
– Danish Ali
Jan 18 at 12:55
forms fields are unrelated.
– Gandalf
Jan 18 at 12:58
add a comment |
Why you are not using loop to upload multiple images?
– Danish Ali
Jan 18 at 12:55
forms fields are unrelated.
– Gandalf
Jan 18 at 12:58
Why you are not using loop to upload multiple images?
– Danish Ali
Jan 18 at 12:55
Why you are not using loop to upload multiple images?
– Danish Ali
Jan 18 at 12:55
forms fields are unrelated.
– Gandalf
Jan 18 at 12:58
forms fields are unrelated.
– Gandalf
Jan 18 at 12:58
add a comment |
1 Answer
1
active
oldest
votes
You can get new file name using
$this->upload->data();
This will return details of uploaded files.
So you can do it like
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 5000;
$config['max_width'] = 2000;
$config['max_height'] = 2000;
$rand_name = 'vehicles'.rand(321,8999).'_'.time();
$config['file_name'] = $rand_name;
$this->load->library('upload', $config);
$this->upload->do_upload('logbook');
$logbook = $this->upload->data();
$logbook_new_filename = $logbook['file_name'];
$this->upload->do_upload('inrep');
$inrep = $this->upload->data();
$inrep_new_filename = $inrep['file_name'];
$this->upload->do_upload('insurance');
$insurance= $this->upload->data();
$insurance_new_filename = $insurance['file_name'];
$this->upload->do_upload('vp');
$vp= $this->upload->data();
$vp_new_filename = $vp['file_name'];
I haven't tested it. But I use like this to get uploaded filename.Hope it will help.
That worked but may i ask$logbook_new_filename = $logbook['file_name'];
what this does
– Gandalf
Jan 18 at 13:42
" $logbook_new_filename " will be name of your new file.
– Cppi Khatri
Jan 18 at 13:43
1
And your final array will be $upload_data = array('logbook'=>$logbook_new_filename,'inrep'=>$inrep_new_filename,'insurance'=>$insurance_new_filename,'vp'=>$vp_new_filename); Now you can use this array in your insert query.
– Cppi Khatri
Jan 18 at 13:50
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54254401%2fcodeigniter-obtain-image-name-for-multiple-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can get new file name using
$this->upload->data();
This will return details of uploaded files.
So you can do it like
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 5000;
$config['max_width'] = 2000;
$config['max_height'] = 2000;
$rand_name = 'vehicles'.rand(321,8999).'_'.time();
$config['file_name'] = $rand_name;
$this->load->library('upload', $config);
$this->upload->do_upload('logbook');
$logbook = $this->upload->data();
$logbook_new_filename = $logbook['file_name'];
$this->upload->do_upload('inrep');
$inrep = $this->upload->data();
$inrep_new_filename = $inrep['file_name'];
$this->upload->do_upload('insurance');
$insurance= $this->upload->data();
$insurance_new_filename = $insurance['file_name'];
$this->upload->do_upload('vp');
$vp= $this->upload->data();
$vp_new_filename = $vp['file_name'];
I haven't tested it. But I use like this to get uploaded filename.Hope it will help.
That worked but may i ask$logbook_new_filename = $logbook['file_name'];
what this does
– Gandalf
Jan 18 at 13:42
" $logbook_new_filename " will be name of your new file.
– Cppi Khatri
Jan 18 at 13:43
1
And your final array will be $upload_data = array('logbook'=>$logbook_new_filename,'inrep'=>$inrep_new_filename,'insurance'=>$insurance_new_filename,'vp'=>$vp_new_filename); Now you can use this array in your insert query.
– Cppi Khatri
Jan 18 at 13:50
add a comment |
You can get new file name using
$this->upload->data();
This will return details of uploaded files.
So you can do it like
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 5000;
$config['max_width'] = 2000;
$config['max_height'] = 2000;
$rand_name = 'vehicles'.rand(321,8999).'_'.time();
$config['file_name'] = $rand_name;
$this->load->library('upload', $config);
$this->upload->do_upload('logbook');
$logbook = $this->upload->data();
$logbook_new_filename = $logbook['file_name'];
$this->upload->do_upload('inrep');
$inrep = $this->upload->data();
$inrep_new_filename = $inrep['file_name'];
$this->upload->do_upload('insurance');
$insurance= $this->upload->data();
$insurance_new_filename = $insurance['file_name'];
$this->upload->do_upload('vp');
$vp= $this->upload->data();
$vp_new_filename = $vp['file_name'];
I haven't tested it. But I use like this to get uploaded filename.Hope it will help.
That worked but may i ask$logbook_new_filename = $logbook['file_name'];
what this does
– Gandalf
Jan 18 at 13:42
" $logbook_new_filename " will be name of your new file.
– Cppi Khatri
Jan 18 at 13:43
1
And your final array will be $upload_data = array('logbook'=>$logbook_new_filename,'inrep'=>$inrep_new_filename,'insurance'=>$insurance_new_filename,'vp'=>$vp_new_filename); Now you can use this array in your insert query.
– Cppi Khatri
Jan 18 at 13:50
add a comment |
You can get new file name using
$this->upload->data();
This will return details of uploaded files.
So you can do it like
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 5000;
$config['max_width'] = 2000;
$config['max_height'] = 2000;
$rand_name = 'vehicles'.rand(321,8999).'_'.time();
$config['file_name'] = $rand_name;
$this->load->library('upload', $config);
$this->upload->do_upload('logbook');
$logbook = $this->upload->data();
$logbook_new_filename = $logbook['file_name'];
$this->upload->do_upload('inrep');
$inrep = $this->upload->data();
$inrep_new_filename = $inrep['file_name'];
$this->upload->do_upload('insurance');
$insurance= $this->upload->data();
$insurance_new_filename = $insurance['file_name'];
$this->upload->do_upload('vp');
$vp= $this->upload->data();
$vp_new_filename = $vp['file_name'];
I haven't tested it. But I use like this to get uploaded filename.Hope it will help.
You can get new file name using
$this->upload->data();
This will return details of uploaded files.
So you can do it like
$config['upload_path'] = './uploads/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = 5000;
$config['max_width'] = 2000;
$config['max_height'] = 2000;
$rand_name = 'vehicles'.rand(321,8999).'_'.time();
$config['file_name'] = $rand_name;
$this->load->library('upload', $config);
$this->upload->do_upload('logbook');
$logbook = $this->upload->data();
$logbook_new_filename = $logbook['file_name'];
$this->upload->do_upload('inrep');
$inrep = $this->upload->data();
$inrep_new_filename = $inrep['file_name'];
$this->upload->do_upload('insurance');
$insurance= $this->upload->data();
$insurance_new_filename = $insurance['file_name'];
$this->upload->do_upload('vp');
$vp= $this->upload->data();
$vp_new_filename = $vp['file_name'];
I haven't tested it. But I use like this to get uploaded filename.Hope it will help.
answered Jan 18 at 13:10
Cppi KhatriCppi Khatri
526
526
That worked but may i ask$logbook_new_filename = $logbook['file_name'];
what this does
– Gandalf
Jan 18 at 13:42
" $logbook_new_filename " will be name of your new file.
– Cppi Khatri
Jan 18 at 13:43
1
And your final array will be $upload_data = array('logbook'=>$logbook_new_filename,'inrep'=>$inrep_new_filename,'insurance'=>$insurance_new_filename,'vp'=>$vp_new_filename); Now you can use this array in your insert query.
– Cppi Khatri
Jan 18 at 13:50
add a comment |
That worked but may i ask$logbook_new_filename = $logbook['file_name'];
what this does
– Gandalf
Jan 18 at 13:42
" $logbook_new_filename " will be name of your new file.
– Cppi Khatri
Jan 18 at 13:43
1
And your final array will be $upload_data = array('logbook'=>$logbook_new_filename,'inrep'=>$inrep_new_filename,'insurance'=>$insurance_new_filename,'vp'=>$vp_new_filename); Now you can use this array in your insert query.
– Cppi Khatri
Jan 18 at 13:50
That worked but may i ask
$logbook_new_filename = $logbook['file_name'];
what this does– Gandalf
Jan 18 at 13:42
That worked but may i ask
$logbook_new_filename = $logbook['file_name'];
what this does– Gandalf
Jan 18 at 13:42
" $logbook_new_filename " will be name of your new file.
– Cppi Khatri
Jan 18 at 13:43
" $logbook_new_filename " will be name of your new file.
– Cppi Khatri
Jan 18 at 13:43
1
1
And your final array will be $upload_data = array('logbook'=>$logbook_new_filename,'inrep'=>$inrep_new_filename,'insurance'=>$insurance_new_filename,'vp'=>$vp_new_filename); Now you can use this array in your insert query.
– Cppi Khatri
Jan 18 at 13:50
And your final array will be $upload_data = array('logbook'=>$logbook_new_filename,'inrep'=>$inrep_new_filename,'insurance'=>$insurance_new_filename,'vp'=>$vp_new_filename); Now you can use this array in your insert query.
– Cppi Khatri
Jan 18 at 13:50
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54254401%2fcodeigniter-obtain-image-name-for-multiple-files%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Why you are not using loop to upload multiple images?
– Danish Ali
Jan 18 at 12:55
forms fields are unrelated.
– Gandalf
Jan 18 at 12:58