The code below keeps putting images in the folder assets/images/photoAlbums
, but i feel like it should be putting them in the folder assets/images/photoAlbums/$album
.
When I first load up the page, it displays the url with controller/addPhoto/Testing
, and the addPhoto view just has a form where a user chooses a file and clicks submit. It submits it to this same controller function addPhoto, only when you submit the page, it doesn't have the Testing
segment in the URL anymore and that is the reason it keeps uploading to assets/images/photoAlbums
.
I think all I need to do is pass the segment when I load the view again, but I can't figu开发者_如何学JAVAre out how to pass a segment when I load the view.
/**
* addPhoto - function which shows the add photo page
*/
function addPhoto()
{
$album = $this->uri->segment(3);
$config['upload_path'] = './assets/images/photoAlbums/'.$album.'/';
$config['allowed_types'] = 'jpg|jpeg|pjpeg';
$config['max_size'] = '2048'; // that's 2MBs
$config['max_width'] = '1200';
$config['max_height'] = '1200';
$config['remove_space'] = TRUE;
$config['overwrite'] = TRUE;
echo "album = ".$album;
echo "config = ".$config['upload_path'];
$this->load->library('upload', $config);
if(!$this->upload->do_upload('userFile')) { // if there are errors...
//echo "fail";
$content_data['error'] = array('error' => $this->upload->display_errors());
$content_data['data'] = array('upload_data'=>$this->upload->data());
$content_data['title'] = ' | Rochester Water Ski Show Team';
$content_data['firstName'] = $this->session->userdata('firstName');
$data['sess'] = $this->session;
$data['content'] = $this->load->view('member/addPhoto', $content_data, true);
$this->load->view('template/admin', $data);
} else { // else there are NO errors
//echo "success";
$content_data['data'] = array('upload_data'=>$this->upload->data());
$content_data['title'] = ' | Rochester Water Ski Show Team';
$content_data['firstName'] = $this->session->userdata('firstName');
$data['sess'] = $this->session;
$data['content'] = $this->load->view('member/addPhoto_success', $content_data, true);
$this->load->view('template/admin', $data);
}
}
You don't need to retrieve the segment with $this->uri->segment(3).
If you call your controller as you do, controller/addPhoto/Testing
, you can retrive the parameter automatically in your method:
function addPhoto($album) {
echo $album; // output: 'Testing';
}
$album is now already available inside your method.
If your parameter is somewhat static, you can use the form method to pass said paramenter, like echo form_open('controller/addPhoto/albumname');
.
If you want it dynamic, then you can twist a bit the logic and pass the name using an hidden field, in this way your method will be called without parameters echo form_open('controller/addPhoto')
, and you retrieve the album name through $this->input->post('myhiddeninput')
.
If you feel I misunderstood something just let know.
精彩评论