當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Upload類代碼示例

本文整理匯總了PHP中Upload的典型用法代碼示例。如果您正苦於以下問題:PHP Upload類的具體用法?PHP Upload怎麽用?PHP Upload使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Upload類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: addUser

 public function addUser()
 {
     if (IS_POST) {
         //上傳頭像的路徑
         $path = 'Upload/UserImages/' . date("Y/m/d");
         $data = $_POST;
         $data['password'] = md5($data['password']);
         $data['create_time'] = time();
         $user = K('User');
         if (!$user->valid($data['username'])) {
             if (isset($_FILES['user_img'])) {
                 $upload = new Upload($path);
                 $files = $upload->upload();
             }
             $data['user_img'] = $files[0]['path'];
             if ($user->addUser($data)) {
                 $this->success('用戶添加成功!', U('listUser', array('p' => 1)));
             } else {
                 $this->error('用戶添加失敗了,請檢查填寫信息!', U('addUser'));
             }
         } else {
             $this->error('用戶添加失敗,請檢查填寫信息!', U('addUser'));
         }
     }
     $this->display();
 }
開發者ID:sujinw,項目名稱:webPHP,代碼行數:26,代碼來源:UserController.class.php

示例2: action_index

 /**
  * 首頁
  *
  */
 public function action_index()
 {
     if (!empty($_FILES)) {
         $savePath = DOCROOT . 'src_csv/' . $this->auth['uid'] . '/';
         // 保存目錄
         $upload = new Upload(array('size' => 10240, 'ext' => array('csv')));
         $upload->set_path($savePath);
         try {
             $result = $upload->save($_FILES['upload_file']);
             $date = array($this->auth['uid'], $this->auth['username'], $result['name'], $result['saveName'], $result['size'], date('Y-m-d H:i:s'));
             $row = DB::insert('imgup_movestore', array('uid', 'uname', 'csv_file', 'src_file', 'freesize', 'upload_time'))->values($date)->execute();
             $content = $this->changeCharacter($savePath . $result['saveName']);
             //preg_match_all("/(src)=[\"|'| ]{0,}((https?\:\/\/.*?)([^>]*[^\.htm]\.(gif|jpg|bmp|png)))/i",$content, $match);
             //preg_match_all("/[\"|'| ]{0,}((https?\:\/\/[a-zA-Z0-9_\.\/]*?)([^<\>]*[^\.htm]\.(gif|jpg|bmp|png)))/i", $content, $match);
             preg_match_all("/\\<img.*?src\\=[\"\\']+[ \t\n]*(https?\\:\\/\\/.*?)[ \t\n]*[\"\\']+[^>]*>/i", $content, $match);
             $imgArr = array_unique($match[1]);
             foreach ($imgArr as $value) {
                 # 去除本站的圖片地址
                 if (!preg_match("/^http:\\/\\/[\\w\\.\\-\\_]*wal8\\.com/i", $value)) {
                     DB::insert('store_imgs', array('sid', 'url', 'add_time', 'uid'))->values(array($row[0], $value, time(), $this->auth['uid']))->execute();
                 }
             }
             $link[] = array('text' => '返回', 'href' => '/shopmove');
             $this->show_message('上傳' . $result['name'] . '文件成功', 1, $link);
         } catch (Exception $e) {
             $link[] = array('text' => '返回', 'href' => '/shopmove');
             $this->show_message($e->getMessage(), 0, $link);
         }
     }
 }
開發者ID:BGCX261,項目名稱:zhongyycode-svn-to-git,代碼行數:34,代碼來源:shopmove.php

示例3: actionUpload

 /**
  * 編輯器文件上傳
  */
 public function actionUpload()
 {
     if (XUtils::method() == 'POST') {
         $file = XUpload::upload($_FILES['imgFile']);
         if (is_array($file)) {
             $model = new Upload();
             $model->user_id = intval($admini['userId']);
             $model->file_name = CHtml::encode($file['pathname']);
             $model->thumb_name = CHtml::encode($file['paththumbname']);
             $model->real_name = CHtml::encode($file['name']);
             $model->file_ext = $file['extension'];
             $model->file_mime = $file['type'];
             $model->file_size = $file['size'];
             $model->save_path = $file['savepath'];
             $model->hash = $file['hash'];
             $model->save_name = $file['savename'];
             $model->create_time = time();
             if ($model->save()) {
                 exit(CJSON::encode(array('error' => 0, 'url' => Yii::app()->baseUrl . '/' . $file['pathname'])));
             } else {
                 @unlink($file['pathname']);
                 @unlink($file['paththumbname']);
                 exit(CJSON::encode(array('error' => 1, 'message' => '上傳錯誤')));
             }
         } else {
             exit(CJSON::encode(array('error' => 1, 'message' => '上傳錯誤:' . $file)));
         }
     }
 }
開發者ID:tecshuttle,項目名稱:51qsk,代碼行數:32,代碼來源:XUserBase.php

示例4: createquestion

 function createquestion($params, $file_name = '')
 {
     //print_r($_FILES);
     //exit();
     if ($file_name != '') {
         $upload = new Upload($file_name, '../lib/uploads/', 5242880);
         $upload->file_prefix = 'closeup_' . $this->rand_string();
         $upload_result = $upload->upload_process();
         if ($upload->upload_error) {
             $response = $upload->upload_error;
         } else {
             $params['filename'] = $upload_result['name'];
             $fields = array_keys($params);
             $values = $params;
             $tablename = "questions";
             $response = $this->InsertOpt($tablename, $fields, $values);
         }
     } else {
         $fields = array_keys($params);
         $values = $params;
         $tablename = "questions";
         $response = $this->InsertOpt($tablename, $fields, $values);
     }
     return $response;
 }
開發者ID:nimboya,項目名稱:SingePageTestEngine,代碼行數:25,代碼來源:cms.php

示例5: share_validation

 public function share_validation()
 {
     $this->load->library('form_validation');
     $this->load->helper('form');
     $this->form_validation->set_error_delimiters('<div class="alert alert-error"><button type="button" class="close" data-dismiss="alert">×</button>', '</div>');
     //mise en place des regles
     $this->form_validation->set_rules('keywords', 'Mots-clés', 'required|encode_php_tags|htmlspecialchars|trim|xss_clean|max_length[200]');
     $this->form_validation->set_rules('description', 'Description', 'required|encode_php_tags|htmlspecialchars|trim|xss_clean|max_length[300]');
     if ($this->form_validation->run() == FALSE) {
         //on affiche le formulaire
         $this->share();
     } else {
         // upload du fichier
         $file_up = new Upload();
         $user = unserialize($this->session->userdata('user_obj'));
         if ($file_up->upload_file($user->id, array('userfile'))) {
             // Création fichier
             $file = new File();
             $file->id_user = $user->id;
             $file->desc = $this->input->post('description');
             $file->keywords = $this->input->post('keywords');
             $file->url = $file_up->files_uploaded[0][0];
             $file->type = $file_up->files_uploaded[0][1];
             //sauvegarde du fichier
             $file->save();
             //notification
             $this->session->set_userdata('notif_ok', '<div class="alert alert-success"><button type="button" class="close" data-dismiss="alert">×</button><strong>Bravo! </strong> Votre partage a été réussi.</div>');
             //redirection sur l'actualité
             redirect('flux', 'refresh');
         } else {
             //on affiche le formulaire
             $this->share();
         }
     }
 }
開發者ID:googlecode-mirror,項目名稱:bdm-wavebook-2012,代碼行數:35,代碼來源:flux.php

示例6: upload

 /**
  * 文件上傳
  * @param  array  $files   要上傳的文件列表(通常是$_FILES數組)
  * @param  array  $setting 文件上傳配置
  * @param  string $driver  上傳驅動名稱
  * @param  array  $config  上傳驅動配置
  * @return array           文件上傳成功後的信息
  */
 public function upload($files, $setting, $driver = 'Local', $config = null)
 {
     $setting['callback'] = array($this, 'isFile');
     $setting['removeTrash'] = array($this, 'removeTrash');
     $Upload = new Upload($setting, $driver, $config);
     $info = $Upload->upload($files);
     if ($info) {
         //文件上傳成功,記錄文件信息
         foreach ($info as $key => &$value) {
             /* 已經存在文件記錄 */
             if (isset($value['id']) && is_numeric($value['id'])) {
                 continue;
             }
             /* 記錄文件信息 */
             $value['path'] = substr($setting['rootPath'], 1) . $value['savepath'] . $value['savename'];
             //在模板裏的url路徑
             if ($this->create($value) && ($id = $this->add())) {
                 $value['id'] = $id;
             }
             // else {
             //     //TODO: 文件上傳成功,但是記錄文件信息失敗,需記錄日誌
             //     unset($info[$key]);
             // }
         }
         return $info;
         //文件上傳成功
     } else {
         $this->error = $Upload->getError();
         return false;
     }
 }
開發者ID:Germey,項目名稱:SimpleCMS,代碼行數:39,代碼來源:PictureMappingModel.class.php

示例7: hd_uploadify

 /**
  * Uploadify上傳文件處理
  */
 public function hd_uploadify()
 {
     $uploadModel = M('upload');
     //上傳文件類型
     if (isset($_POST['type'])) {
         $type = str_replace('*.', '', $_POST['type']);
         $type = explode(';', $type);
     } else {
         $type = array();
     }
     $size = Q('size') ? Q('size') : C('allow_size');
     $upload = new Upload(Q('upload_dir'), $type, $size);
     $file = $upload->upload();
     if (!empty($file)) {
         $file = $file[0];
         $file['uid'] = $_SESSION['user']['uid'];
         //圖片加水印
         if ($file['image'] && Q('water')) {
             $img = new Image();
             $img->water($file['path']);
         }
         //寫入upload表
         $uploadModel->add($file);
         $data = $file;
         $data['status'] = 1;
     } else {
         $data['status'] = 0;
         $data['message'] = $upload->error;
     }
     echo json_encode($data);
     exit;
 }
開發者ID:suhanyujie,項目名稱:spider,代碼行數:35,代碼來源:ContentUploadController.class.php

示例8: updateImage

        return $this->db->lastInsertId();
    }
    /**
	* Update image
	*/
    public function updateImage($id)
    {
        $ruler = new Ruler($id);
        if ($ruler->Background == null) {
            return false;
        }
        require_once 'core/class.upload/class.upload.php';
        $templates = DIR_DBIMAGES . 'ruler/templates/';
        $results = DIR_DBIMAGES . 'ruler/results/';
        $iu = new Upload($templates . $ruler->Background);
        $iu->file_overwrite = true;
        $iu->file_new_name_body = $id;
        $iu->file_new_name_ext = 'jpg';
        $iu->image_unsharp = true;
        $iu->image_border = '0 0 16 0';
        $iu->image_border_color = strtolower($ruler->Color) == '#ffffff' ? '#333333' : '#ffffff';
        $iu->image_watermark = $templates . $ruler->Slider;
        $iu->image_watermark_y = 35;
        $iu->image_watermark_x = $ruler->getSliderPosition();
        $iu->Process($results);
        $image = imagecreatefromjpeg($results . $id . '.jpg');
開發者ID:AleksandrChukhray,項目名稱:good_deals,代碼行數:26,代碼來源:Ruler.php

示例9: store

 /**
  * Upload the file and store
  * the file path in the DB.
  */
 public function store()
 {
     // Rules
     $rules = array('name' => 'required', 'file' => 'required|max:20000');
     $messages = array('max' => 'Please make sure the file size is not larger then 20MB');
     // Create validation
     $validator = Validator::make(Input::all(), $rules, $messages);
     if ($validator->fails()) {
         return Redirect::back()->withErrors($validator)->withInput();
     }
     $directory = "uploads/files/";
     // Before anything let's make sure a file was uploaded
     if (Input::hasFile('file') && Request::file('file')->isValid()) {
         $current_file = Input::file('file');
         $filename = Auth::id() . '_' . $current_file->getClientOriginalName();
         $current_file->move($directory, $filename);
         $file = new Upload();
         $file->user_id = Auth::id();
         $file->project_id = Input::get('project_id');
         $file->name = Input::get('name');
         $file->path = $directory . $filename;
         $file->save();
         return Redirect::back();
     }
     $upload = new Upload();
     $upload->user_id = Auth::id();
     $upload->project_id = Input::get('project_id');
     $upload->name = Input::get('name');
     $upload->path = $directory . $filename;
     $upload->save();
     return Redirect::back();
 }
開發者ID:pradeep1899,項目名稱:ALM_Task_Manager,代碼行數:36,代碼來源:FilesController.php

示例10: profileActAction

 public function profileActAction()
 {
     $m['realname'] = $this->getPost('realname');
     $m['provinceID'] = $this->getPost('areaProvince');
     $m['cityID'] = $this->getPost('areaCity');
     $m['regionID'] = $this->getPost('areaRegion');
     $m['province'] = $this->load('Province')->getProvinceNameByID($m['provinceID']);
     $m['city'] = $this->load('City')->getCityNameByID($m['cityID']);
     if ($m['regionID']) {
         $m['region'] = $this->load('Region')->getRegionNameByID($m['regionID']);
     }
     $code = $this->m_user->UpdateByID($m, USER_ID);
     // Upload avatar if selected
     if ($_FILES['avatar']['name']) {
         $fileName = CUR_TIMESTAMP;
         $up = new Upload($_FILES['avatar'], UPLOAD_PATH . '/');
         $result = $up->upload($fileName);
         if ($result == 1) {
             $m['avatar'] = $fileName . '.' . $up->extension;
             $this->m_user->UpdateByID($m, USER_ID);
         } else {
             jsAlert($result);
         }
     }
     if (FALSE === $code && $result != 1) {
         jsAlert('編輯個人信息失敗, 請重試');
     }
     $this->redirect('/user/profile/edit');
 }
開發者ID:xinuxZ,項目名稱:YOF,代碼行數:29,代碼來源:Profile.php

示例11: addphotoAction

 public function addphotoAction()
 {
     $db = new Db();
     $this->view->pageHeading = "What are you wearing today?";
     if ($this->getRequest()->isPost()) {
         $request = $this->getRequest();
         $myform = new Form_Upload();
         if ($myform->isValid($request->getPost())) {
             $dataForm = $myform->getValues();
             $myObj = new Upload();
             $Result = $myObj->SaveImage($dataForm);
             if ($Result == 1) {
                 //echo "dsg"; die;
                 $mySession->sucessMsg = "Image saved successfully.";
                 $this->_redirect('post/uploadindex');
             } else {
                 $mySession->errorMsg = "Image you have entered already exists.";
                 $this->view->myform = $myform;
                 $this->render('upload');
             }
         } else {
             $this->view->myform = $myform;
             $this->render('upload');
         }
     } else {
         $this->_redirect('post/upload');
     }
 }
開發者ID:Alexeykolobov,項目名稱:php,代碼行數:28,代碼來源:PostController.php

示例12: hd_uploadify

 /**
  * Uploadify上傳文件處理
  */
 public function hd_uploadify()
 {
     $uploadModel = M('upload');
     //開啟裁切
     C('UPLOAD_IMG_RESIZE_ON', true);
     C('upload_img_max_width', $_POST['upload_img_max_width']);
     C('upload_img_max_height', $_POST['upload_img_max_height']);
     $upload = new Upload(Q('post.upload_dir'), array(), array(), Q("water", null, "intval"));
     $file = $upload->upload();
     if (!empty($file)) {
         $file = $file[0];
         $file['uid'] = session('uid');
         $data['stat'] = 1;
         $data['url'] = __ROOT__ . '/' . $file['path'];
         $data['path'] = $file['path'];
         $data['filename'] = $file['filename'];
         $data['name'] = $file['name'];
         $data['basename'] = $file['basename'];
         $data['thumb'] = array();
         $data['isimage'] = $file['image'];
         //寫入upload表
         $uploadModel->add($file);
     } else {
         $data['stat'] = 0;
         $data['msg'] = $upload->error;
     }
     echo json_encode($data);
     exit;
 }
開發者ID:jyht,項目名稱:v5,代碼行數:32,代碼來源:ContentUploadControl.class.php

示例13: replace

 public function replace($id = null)
 {
     if (!get('_csrf') or !csrf(get('_csrf'))) {
         return response::error('unauthenticated access');
     }
     $filename = get('filename');
     $file = $this->file($id, $filename);
     $blueprint = blueprint::find($this->page($id));
     $upload = new Upload($file->root(), array('overwrite' => true, 'accept' => function ($upload) use($file) {
         if ($upload->mime() != $file->mime()) {
             throw new Error(l('files.replace.error.type'));
         }
     }));
     if ($file = $upload->file()) {
         try {
             $this->checkUpload($file, $blueprint);
             kirby()->trigger('panel.file.replace', $file);
             return response::success('success');
         } catch (Exception $e) {
             $file->delete();
             return response::error($e->getMessage());
         }
     } else {
         return response::error($upload->error()->getMessage());
     }
 }
開發者ID:LucasFyl,項目名稱:korakia,代碼行數:26,代碼來源:files.php

示例14: asignar_cotizacion

 function asignar_cotizacion($id_equipo, $placa_inventario)
 {
     App::import('Vendor', 'upload', array('file' => 'class.upload.php'));
     $this->autoLayout = false;
     $this->autoRender = false;
     $datos_json = array('resultado' => false, 'id' => '', 'nombre_archivo' => '');
     if (!empty($_FILES) && !empty($id_equipo) && !empty($placa_inventario)) {
         if (!empty($_FILES['cotizacion']['name'])) {
             $handle = new Upload($_FILES['cotizacion']);
             if ($handle->uploaded) {
                 $handle->file_overwrite = true;
                 $handle->file_safe_name = false;
                 $handle->file_auto_rename = false;
                 $handle->file_new_name_body = 'cotizacion(' . $this->Cotizacion->getNextAutoIncrement() . ')_' . $placa_inventario;
                 $handle->Process('equipos/cotizaciones');
                 if ($handle->processed) {
                     $this->data['Cotizacion']['nombre_archivo'] = $handle->file_dst_name;
                     $this->data['Cotizacion']['id_equipo'] = $id_equipo;
                     $this->data['Cotizacion']['placa_inventario'] = $placa_inventario;
                     if ($this->Cotizacion->save($this->data)) {
                         $datos_json['resultado'] = true;
                         $datos_json['id'] = $this->Cotizacion->id;
                         $datos_json['nombre_archivo'] = $this->data['Cotizacion']['nombre_archivo'];
                     }
                 }
                 $handle->Clean();
             }
         }
     }
     return json_encode($datos_json);
 }
開發者ID:hongo-de-yuggoth,項目名稱:SIMAU,代碼行數:31,代碼來源:cotizaciones_controller.php

示例15: addHander

 public function addHander()
 {
     // p($_FILES);
     // p($_POST);
     preg_match_all('/<\\s*img\\s+[^>]*?src\\s*=\\s*(\'|\\")(.*?)\\">/i', $_POST['details'], $result, PREG_SET_ORDER);
     $dir = MYPHP_TEMP_PATH . "/Article/" . $_POST['column_id'] . '/' . $_POST['category_id'];
     is_dir($dir) || mkdir($dir, 0777, true);
     chmod($dir, 0777);
     $aid = (int) file_get_contents(MYPHP_TEMP_PATH . '/Dbid/Article/Article/dbid.txt');
     $fileName = $dir . '/' . date('Y-m-d') . '-' . $_POST['column_id'] . '-' . $_POST['category_id'] . '-' . ($aid + 1) . '.txt';
     $data = array();
     foreach ($result as $v) {
         $data[] = $v[0];
     }
     // p($fileName);die;
     file_put_contents($fileName, serialize($data));
     $details = preg_replace('/<\\s*img\\s+[^>]*?src\\s*=\\s*(\'|\\")(.*?)\\">/i', "<baseImg/>", $_POST['details']);
     if (isset($_FILES['thumb'])) {
         $upload = new Upload('Upload/Article/images/' . date("Y/m/d"));
         $files = $upload->upload();
     }
     // p($files);
     // die;
     $articleData = array('column_id' => $_POST['column_id'], 'category_id' => $_POST['category_id'], 'title' => $_POST['title'], 'tags' => $_POST['tags'], 'recommend' => $_POST['recommend'], 'author' => isset($_POST['author']) ? $_POST['author'] : $_SESSION['uname'], 'source' => $_POST['source'], 'details' => $_POST['details'], 'display' => $_POST['display'], 'thumb' => empty($files[0]['path']) ? "" : $files[0]['path'], 'image' => $fileName, 'create_time' => time());
     $articleData['details'] = $details;
     if (K('Article')->addArticle($articleData)) {
         $this->success('文章添加成功', __APP__ . '?c=Article&a=listArticle');
     } else {
         $this->error('文章添加失敗');
     }
 }
開發者ID:sujinw,項目名稱:webPHP,代碼行數:31,代碼來源:ArticleController.class.php


注:本文中的Upload類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。