首先说明 我用的是CI框架 1.7.2版本,如果在2.0 和3.0版本请自行测试
//处理上传文件
//$fileNewName 对应数据库 存储图片字段名
//$fileOldName 客户端传来的 图片名
//$fileCount 上传图片多少张
//$orderId 订单编号
function handle_upload_file($fileNewName, $fileOldName, $fileCount, $orderId, $orderTime=0, $fileTime=1){
//var_dump($fileOldName);exit;
$orderTime = $orderTime? $orderTime:time();
$this->config->load('upload_conf', true);
$config = $this->config->item('file_up_conf', 'upload_conf');
$config['upload_path'] = './file_box/uploads/'.$this->name.'/'.date('Y-m-d', $orderTime).'/'.$orderId;
if(!is_dir($config['upload_path'])){
if(!@mkdir($config['upload_path'], 0777, true)){
message_msg('创建图片文件夹失败!');
}
}
$file = array();
if($fileCount != 1){
for($fileNumber=1; $fileNumber<=$fileCount; $fileNumber++){
$fileOldNameNumber = $fileOldName.$fileNumber;
if($_FILES[$fileOldNameNumber]['error'][0] == 0){
//图片大小不能大于500K
if($_FILES[$fileOldNameNumber]['size'][0]/1024 <= 500){
$fileInfo = multiples($config['upload_path'], $config, $fileOldNameNumber);
if($fileInfo){
$file[$fileNewName.$fileNumber] = serialize($fileInfo[0]['file_name']);
}
}else{
message_msg('图片尺寸不能大于500K,请重新选择第'.$fileNumber.'张图片!');
}
}
}
if($file && $fileTime){
$file[$fileNewName.'time'] = time();
}
}else{
if($_FILES[$fileOldName]['error'][0] == 0){
$fileInfo = multiples($config['upload_path'], $config, $fileOldName);
if($fileInfo){
$file[$fileNewName] = serialize($fileInfo[0]['file_name']);
}
}
}
return $file;
}