2011-05-18 236 views
3

我想用項目ID做一個文件夾,然後我必須使該子文件夾的ID和在我已添加兩個文件和兩個圖像的子文件夾.... 子文件夾的名稱是沒有擴展名的文件名之一.. 我該怎麼辦? 我的代碼: 功能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($錯誤); } } } 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; 
} 

}

+1

代碼超載!你能提取與你的問題有關的碎片而不是所有碎片嗎? – 2011-05-18 10:27:48

回答

0

這可以幫助你

function rmkdir($path) { 
     $path = str_replace("\\", "/", $path); 
     $path = explode("/", $path); 

     $rebuild = ''; 
     foreach($path AS $p) { 

      if(strstr($p, ":") != false) { 
       echo "\nExists : in $p\n"; 
       $rebuild = $p; 
       continue; 
      } 
      $rebuild .= "/$p"; 
      echo "Checking: $rebuild\n"; 
      if(!is_dir($rebuild)) mkdir($rebuild); 
     } 
    } 
相關問題