function upload_pic($file = array(), $other = array()) { if (!$file || !$other) { return false; } $upload = new upload("pic"); $upload->out_file_dir = "./statics/images/idea"; $upload->out_file_name = "idea" . time(); $upload->upload_process(); $error_no = $upload->error_no; if ($error_no > 0) { return flase; } $other["add_time"] = time(); $other["location"] = trim($upload->saved_upload_name, "."); $other["belong_to"] = "idea"; $rs = daocall("admin", "insert_pic", array($other)); if (!$rs) { return false; } return true; }
public function upload($field = 'file', $directoryExtend = '', $required = false, $resize = false, $watermark = '', $watermarkOver = 0, $watermarkPosition = '') { $file = ''; if (isset($_FILES[$field]['name']) && strlen($_FILES[$field]['name']) > 3) { recursive_mkdir(DATA_SERVER_PATH . "/uploads/" . $this->uploadFileDirectory . $directoryExtend); $upload = new upload(); $upload->upload_form_field = $field; $upload->out_file_dir = DATA_SERVER_PATH . "/uploads/" . $this->uploadFileDirectory . $directoryExtend; $upload->max_file_size = $this->maxFileSize; $upload->make_script_safe = 1; $upload->allowed_file_ext = $this->fileExt; $upload->upload_process(); if ($upload->error_no) { switch ($upload->error_no) { case 1: // 无上传 return "error_no_file_upload"; exit; case 2: // 无效的扩展名 return "error_invalid_file_ext"; exit; case 3: // 太大... return "error_file_too_big"; exit; case 4: // 无法移动上传的文件 return "error_no_file_upload"; exit; } } $file = substr($upload->saved_upload_name, strlen(DATA_SERVER_PATH . "/uploads/" . $this->uploadFileDirectory . $directoryExtend)); $this->lastUploadedFile = $file; if ($resize) { $this->resizeImages($file, $directoryExtend, $watermark, $watermarkOver, $watermarkPosition); } } elseif ($required) { return 'error_file_not_set'; } return $file; }