2011-10-05 50 views
0

的笨2和uploadify 2個工作,但我想存儲在MySQL的香港專業教育學院完成2種方法的文件名笨+ uploadify店名在MySQL

第一種方法使用AJAX

'onComplete' : function(event, ID, fileObj, response, data) { 
    $.ajax({ 
     type: "POST", 
     url: "<?php echo site_url('upload/file_upload'); ?>" , 
     data: {filename: fileObj.name,admin_id: $('#admin_id').val(),client_id: $('#client_id').val(),studio_id: $('#studio_id').val()}, 
     success: function(data){ 
      $('#status-message').text(data.filesUploaded + ' files uploaded, ' + data.errors + ' errors.'); 
     } 
    }); 
    } 

//CI Controller and Models 

    public function file_upload() 
    { 

      $data = array(
      'admin_id' => '123',//$this->session->userdata('user_id'), 
      'filename' => $this->input->post('file_name'), 
      'studio_id' => $this->input->post('studio_id'), 
      'client_id' => $this->input->post('client_id') 
     ); 

     $this->file_upload_model->add($data); 

    } 

Model 

class File_upload_model{ 

function add($data){ 

    $this->db->insert('upload_images',$data); 

} 
} 

第二種方法 如果(!空($ _ FILES)){

$path = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; 

//$client_id = $_GET['client_id']; 

$file_temp = $_FILES['Filedata']['tmp_name']; 

$file_name = prep_filename($_FILES['Filedata']['name']); 

$file_ext = get_extension($_FILES['Filedata']['name']); 

$real_name = $file_name; 

$newf_name = set_filename($path, $file_name, $file_ext); 

$file_size = round($_FILES['Filedata']['size']/1024, 2); 

$file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES['Filedata']['type']); 

$file_type = strtolower($file_type); 

$targetFile = str_replace('//','/',$path) . $newf_name; 

move_uploaded_file($file_temp,$targetFile); 



$filearray = array(); 

$filearray['file_name'] = $newf_name; 

$filearray['real_name'] = $real_name; 

$filearray['file_ext'] = $file_ext; 

$filearray['file_size'] = $file_size; 

$filearray['file_path'] = $targetFile; 

$filearray['file_temp'] = $file_temp; 

//$filearray['client_id'] = $client_id; 



$json_array = json_encode($filearray); 

echo $json_array; 
$dbhost = "localhost"; 
$dbname = "photoproof"; 
$dbuser = "root"; 
$dbpass = "password";   
mysql_connect ($dbhost, $dbuser, $dbpass); 
mysql_select_db($dbname); 

mysql_query("INSERT INTO uploaded_images (uploaded_image) VALUES('$file->name') "); 

}else{ 

echo "1"; 

} 

,仍然沒有發生在2種方法我嘗試..希望請給一些想法來解決這個..在此先感謝...

回答

0

您是否嘗試過使用內置的CodeIgniter File Upload Class

+0

肯定的,但文件上傳類僅用於1個文件上傳,我需要多個上傳.....因爲客戶端會上傳圖片2000+這就是爲什麼我使用uploadify一次... – Dreathlord

+1

即使使用uploadify,每次上傳1圖像。 – minboost

0

我加入了查詢解決了這個問題Sa內的js/uplodify.php

if (!empty($_FILES)) { 
$path = $_SERVER['DOCUMENT_ROOT'] . $_REQUEST['folder'] . '/'; 
$admin_id = $_POST['admin_id']; 
$studio_id = $_POST['studio_id']; 
$client_id = $_POST['client_id']; 
$file_temp = $_FILES['Filedata']['tmp_name']; 
$file_name = prep_filename($_FILES['Filedata']['name']); 
$file_ext = get_extension($_FILES['Filedata']['name']); 
$real_name = $file_name; 
$newf_name = set_filename($path, $file_name, $file_ext); 
$file_size = round($_FILES['Filedata']['size']/1024, 2); 
$file_type = preg_replace("/^(.+?);.*$/", "\\1", $_FILES['Filedata']['type']); 
$file_type = strtolower($file_type); 
$targetFile = str_replace('//','/',$path) . $newf_name; 

mysql_connect("localhost", "db_username", "db_password"); 
mysql_select_db("table_name"); 
mysql_query("INSERT INTO uploaded_images  (admin_id,file_name,studio_id,client_id)VALUES('.$admin_id.','.$newf_name.','.$studio_id.','.$client_id.')"); 


move_uploaded_file($file_temp,$targetFile); 

$filearray = array(); 
$filearray['file_name'] = $newf_name; 
$filearray['real_name'] = $real_name; 
$filearray['file_ext'] = $file_ext; 
$filearray['file_size'] = $file_size; 
$filearray['file_path'] = $targetFile; 
$filearray['file_temp'] = $file_temp; 
//$filearray['client_id'] = $client_id; 

$json_array = json_encode($filearray); 
echo $json_array; 



}else{ 
echo "1"; 
}