我希望创建一个文件夹来存放项目ID,然后在该ID下创建子文件夹,在子文件夹中添加两个文件和两个图片... 子文件夹的名称是其中一个文件的名称(不包括扩展名)... 我该怎么做? 我的代码: 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();
// 如果有错误信息,将其显示在页面上 if ($this->form_validation->run() == FALSE) { $errors = validation_errors(); if (!empty($errors)) { flashMsg($errors); } } redirect('main_con'); }
(注:这段代码是一个PHP语言中的表单验证和重定向函数)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;
}
}