Question

I am trying to upload a mp3 and a image type file to server from same form. My controller is :

$uniqueid = uniqid();
$rand = rand(99,199);
$site_string = 'melody';
$original_song_name =   strtolower($_FILES['file_song']['name']);
$original_song_name = str_replace(' ','_',$original_song_name);

$config['upload_path'] = './uploads/songs';
$config['allowed_types'] = 'mp3|gif|jpg|png';
$config['overwrite'] = false;
$config['file_name'] = $uniqueid.$rand.'_'.$original_song_name;

$this->load->library('upload', $config);

if ( ! $this->upload->do_upload('file_song'))
{
    $error = array('error' => $this->upload->display_errors());
    $this->load->view('admin/admin_add_song_view', $error);
}
else
{
    $data = array('song_upload_data' => $this->upload->data());
}
$poster = $_FILES['file_poster']['name'];


if($poster != ''){
    //$config['file_name'] = $uniqueid.$rand.'_'.$poster;
    if ( ! $this->upload->do_upload('file_poster'))
    {
        $error = array('error' => $this->upload->display_errors());
        $this->load->view('admin/admin_add_song_view', $error);
    }
    else
    {
        $pdata = array('poster_upload_data' => $this->upload->data());
    }
    $fileposter = $pdata['poster_upload_data']['file_name'];
}
var_dump($pdata);

my var_dump($pdata) output is :

array (size=1)
  'poster_upload_data' => 
    array (size=14)
      'file_name' => string '52dd0b2a4a20b103_sleep_away1.mp3' (length=32)
      'file_type' => string 'image/jpeg' (length=10)
      'file_path' => string 'C:/wamp/www/ciauth/uploads/songs/' (length=33)
      'full_path' => string 'C:/wamp/www/ciauth/uploads/songs/52dd0b2a4a20b103_sleep_away1.mp3' (length=65)
      'raw_name' => string '52dd0b2a4a20b103_sleep_away1' (length=28)
      'orig_name' => string '52dd0b2a4a20b103_sleep_away.mp3' (length=31)
      'client_name' => string 'Chrysanthemum.jpg' (length=17)
      'file_ext' => string '.mp3' (length=4)
      'file_size' => float 858.78
      'is_image' => boolean true
      'image_width' => int 1024
      'image_height' => int 768
      'image_type' => string 'jpeg' (length=4)
      'image_size_str' => string 'width="1024" height="768"' (length=25)

As you can see, $pdata['poster_upload_data']['file_name'] is the file name of the mp3 file uploaded earlier. How can I change it to desired image file name ? I tried to add $config['file_name'] = $uniqueid.$rand.'_'.$poster; within the loop, but its not changing anything !

No correct solution

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top