i want to make a folder with the project id and then i have to make sub folder for that id and in the sub folder i have add two files and two images.... the name for the sub folder is one of the file's name without extension.. how can i do??? my code: function add_sub_project_ok() {
$i=0;
$query = $this->main_model->select_project();
if($query->num_rows()>0)
{
foreach ($query->result() as $row)
{
$data['adv'][$i]['id']=$row->id;
$data['adv'][$i]['p_name']=$row->p_name;
$data['adv'][$i]['d_link']=base_url().'uploads'.$data['adv'][$i]['id'];
$i++;
}
}
$data['p_name']=$this->input->post('pname');
$file_name = $_FILES['image']['name'];
$config['upload_path'] = 'uploads/'.$this->db->insert_id().'/';
$path=$config['upload_path'];
$config['allowed_types'] = 'gif|jpg|jpeg|png|pjpeg';
$config['max_size'] = '750';
$config['max_width'] = '1920';
$config['max_height'] = '1280';
$this->load->library('upload');
foreach ($_FILES as $key => $value)
{
if (!empty($key['name']))
{
$this->upload->initialize($config);
if (!$this->upload->do_upload($key))
{
$errors = $this->upload->display_errors();
// flashMsg($errors);
}
else
{
$temp = $this->_process_pic();
$data['reg']['FK_add_pname_id']=$data['adv'][$i]['id'];
$data['reg']['img_name']=$temp['imagename'];
$data['reg']['img_name_tn']=$temp['thumbnail'];
$data['reg']['ipa']=$_FILES['ipa']['name'];
$data['reg']['plist']=$_FILES['plist']['name'];
$data['reg']['uname']=$_POST['uname'];
$data['reg']['pass']=$_POST['pass'];
$this->main_model->update($data['reg'],$id);
}
}
}
$this->file_upload($data,$id);
}
function file_upload($data,$id)
{
$data['p_name']=$this->input->post('pname');
$file_name = $_FILES['ipa']['name'];
mkdir('uploads/'.$id.'/'.$file_name);
$config['upload_path'] = 'uploads/'.$id.'/'.$file_name;
$path=$config['upload_path'];
$config['allowed_types'] = 'exe|psd|pdf|xls|ppt|php|php4|php3|js|swf|Xhtml|zip|mid|midi|mp2|mp3|wav|html|htm|txt|rtf|mpeg|mpg|avi|doc|docx|xlsx';
$this->load->library('upload');
foreach ($_FILES as $key => $value)
{
if (!empty($key['name']))
{
$this->upload->initialize($config);
if (!$this->upload->do_upload($key))
{
$errors = $this->upload->display_errors();
// flashMsg($errors); } } } redirect('main_con'); }
function _process_pic() {
//Get File Data Info
$uploads = array($this->upload->data());
$this->load->library('image_lib');
//Move Files To User Folder
foreach ($uploads as $key[] => $value) {
$newimagename = url_title($value['raw_name'] . $value['file_ext'], 'underscore');
move_uploaded_file($value['full_path'], '/uploads/' . $newimagename);
//Creat Thumbnail
$config['image_library'] = 'GD2';
$config['source_image'] = $value['full_path'];
$config['create_thumb'] = TRUE;
$config['thumb_marker'] = '_tn';
$config['master_dim'] = 'width';
$config['quality'] = 75;
$config['maintain_ratio'] = TRUE;
$config['width'] = 100;
$config['height'] = 100;
$config['new_image'] = $newimagename;
$this->image_lib->initialize($config);
$this->image_lib->resize();
if (!$this->image_lib->resize())
echo $this->image_lib->display_errors();
$filesize = $value['file_size'];
$width = $value['image_width'];
$height = $value['image_height'];
$timestamp = time();
$this->image_lib->clear();
$temp['imagename'] = $value['file_name'];
$temp['thumbnail'] = $value['raw_name'] . '_tn' . $value['file_ext'];
return $temp;
}
}
Are you looking for a recursive mkdir?
@mkdir('uploads/'.$id.'/'.$file_name, 0777, true);
http://php.net/manual/en/function.mkdir.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With