本文整理汇总了PHP中upload类的典型用法代码示例。如果您正苦于以下问题:PHP upload类的具体用法?PHP upload怎么用?PHP upload使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了upload类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: handleMenuUpload
public function handleMenuUpload()
{
$filename = $this->user->getMenuFile();
if (!empty($_FILES['input_menu']['tmp_name']) && is_uploaded_file($_FILES['input_menu']['tmp_name'])) {
$validImageTypes = array("jpg", "jpeg", "png", "pdf");
if (filesize($_FILES['input_menu']['tmp_name']) > MAX_IMAGE_UPLOAD_FILESIZE) {
echo "Upload is too big.";
return false;
}
$menuUpload = new upload($_FILES['input_menu']);
$menuUploadFolder = ASSETS_PATH . "downloads/";
$menuFileInfo = pathinfo($_FILES['input_menu']['name']);
$newFilenameBase = $this->user->getStub() . "_menu";
$ext = strtolower(pathinfo($_FILES['input_menu']['name'], PATHINFO_EXTENSION));
if (!in_array($ext, $validImageTypes)) {
echo "invalidImageType";
return false;
}
if ($menuUpload->uploaded) {
## Move uploaded file and resize
$menuUpload->file_new_name_body = $newFilenameBase;
$menuUpload->file_overwrite = true;
$menuUpload->process($menuUploadFolder);
if ($menuUpload->processed) {
$filename = $newFilenameBase . "." . $ext;
} else {
echo $menuUpload->error;
}
} else {
echo $menuUpload->error;
}
}
return $filename;
}
示例2: beforeSave
public function beforeSave($options = array())
{
if (is_numeric(key($this->data['Foto']))) {
$produto_id = $this->data['Foto']['produto_id'];
foreach ($this->data['Foto'] as $key => $foto) {
if (is_numeric($key)) {
if (!empty($foto['tmp_name'])) {
App::uses('upload', 'Vendor');
$imagem = new upload($foto);
if ($imagem->uploaded) {
$imagem->resize = true;
$imagem->imagem_x = 100;
$imagem->imagem_ratio_y = true;
$imagem->process('img/produtos/');
if ($imagem->processed) {
$_foto = array('produto_id' => $produto_id, 'arquivo' => $imagem->file_dst_name);
$this->create();
$this->save($_foto);
} else {
throw new Exception($imagem->error);
}
} else {
throw new Exception($imagem->error);
}
}
}
}
if (!isset($_foto)) {
return false;
}
$this->data['Foto'] = $_foto;
}
}
示例3: nuevo
public function nuevo()
{
//verifica el rol y los permisos de usuario.
$this->_acl->acceso('nuevo_post');
//asigna titulo a la vista
$this->_view->assign('titulo', 'Nuevo Post');
//coloca el archivos js y js.validate.
$this->_view->setJsPlugin(array('jquery.validate'));
$this->_view->setJs(array('nuevo'));
//si el archivo fue mandado entonces se asignan los valores de $_POST a la variable datos.
if ($this->getInt('guardar') == 1) {
$this->_view->assign('datos', $_POST);
//verifica si el post tiene titulo
if (!$this->getTexto('titulo')) {
$this->_view->assign('_error', 'Debe introducir el titulo del post');
$this->_view->renderizar('nuevo', 'post');
exit;
}
//verifica si el post tiene cuerpo
if (!$this->getTexto('cuerpo')) {
$this->_view->assign('_error', 'Debe introducir el cuerpo del post');
$this->_view->renderizar('nuevo', 'post');
exit;
}
$imagen = '';
//verifica si se ha seleccionado un archivo tipo imagen
if ($_FILES['imagen']['name']) {
//se define la ruta de la imagen
$ruta = ROOT . 'public' . DS . 'img' . DS . 'post' . DS;
//Se crea un objeto upload con idioma español.
$upload = new upload($_FILES['imagen'], 'es_Es');
//se especifica el tipo de archivo.
$upload->allowed = array('image/*');
//se define un nombre para el archivo.
$upload->file_new_name_body = 'upl_' . uniqid();
//Se inicia la carga con la ruta destino especificada
$upload->process($ruta);
//si se ha logrado la carga entonces crear una miniatura con upload libreria.
if ($upload->processed) {
$imagen = $upload->file_dst_name;
$thumb = new upload($upload->file_dst_pathname);
$thumb->image_resize = true;
$thumb->image_x = 100;
$thumb->image_y = 70;
$thumb->file_name_body_pre = 'thumb_';
$thumb->process($ruta . 'thumb' . DS);
} else {
$this->_view->assign('_error', $upload->error);
$this->_view->renderizar('nuevo', 'post');
exit;
}
}
//Luego de guardarse la imagen entonces se guarda el post
$this->_post->insertarPost($this->getPostParam('titulo'), $this->getPostParam('cuerpo'), $imagen);
//Se redicciona al index de post.
$this->redireccionar('post');
}
//Se renderiza nuevamente la vista nuevo del post.
$this->_view->renderizar('nuevo', 'post');
}
示例4: upload
/**
* Uploads a new file for the given FileField instance.
*
* @param string $name EAV attribute name
* @throws \Cake\Network\Exception\NotFoundException When invalid slug is given,
* or when upload process could not be completed
*/
public function upload($name)
{
$instance = $this->_getInstance($name);
require_once Plugin::classPath('Field') . 'Lib/class.upload.php';
$uploader = new \upload($this->request->data['Filedata']);
if (!empty($instance->settings['extensions'])) {
$exts = explode(',', $instance->settings['extensions']);
$exts = array_map('trim', $exts);
$exts = array_map('strtolower', $exts);
if (!in_array(strtolower($uploader->file_src_name_ext), $exts)) {
$this->_error(__d('field', 'Invalid file extension.'), 501);
}
}
$response = '';
$uploader->file_overwrite = false;
$folder = normalizePath(WWW_ROOT . "/files/{$instance->settings['upload_folder']}/");
$url = normalizePath("/files/{$instance->settings['upload_folder']}/", '/');
$uploader->process($folder);
if ($uploader->processed) {
$response = json_encode(['file_url' => Router::url($url . $uploader->file_dst_name, true), 'file_size' => FileToolbox::bytesToSize($uploader->file_src_size), 'file_name' => $uploader->file_dst_name, 'mime_icon' => FileToolbox::fileIcon($uploader->file_src_mime)]);
} else {
$this->_error(__d('field', 'File upload error, details: {0}', $uploader->error), 502);
}
$this->viewBuilder()->layout('ajax');
$this->title(__d('field', 'Upload File'));
$this->set(compact('response'));
}
示例5: uploadFileImage
public function uploadFileImage($file, $ruta, $name)
{
if (isset($_FILES[$file]['name'])) {
if ($_FILES[$file]['name']) {
$upload = new upload($_FILES[$file], 'es_ES');
$upload->allowed = array('image/jpg', 'image/jpeg', 'image/png', 'image/gif');
$upload->file_max_size = '524288';
// 512KB
if ($name) {
$upload->file_new_name_body = 'upl_' . $name;
} else {
$upload->file_new_name_body = 'upl_' . sha1(uniqid());
}
$upload->process($ruta);
if ($upload->processed) {
//THUMBNAILS
$imagen = $upload->file_dst_name;
$thumb = new upload($upload->file_dst_pathname);
$thumb->image_resize = true;
$thumb->image_x = 150;
$thumb->image_y = 150;
//$thumb->file_name_body_pre= 'thumb_';
$thumb->process($ruta . 'thumb' . DS);
return true;
} else {
throw new Exception('Error al subir la imagen: ' . $upload->error);
}
}
} else {
return false;
}
}
示例6: updateImage
public function updateImage()
{
require_once 'helpers/upload.php';
$code = '';
if (isset($_POST['id']) && isset($_POST['path'])) {
$id = intval($_POST['id']);
$handle = new upload($_FILES['image_field']);
if ($handle->uploaded) {
$handle->file_new_name_body = $id;
$handle->image_resize = true;
$handle->image_x = 100;
$handle->image_ratio_y = true;
$handle->file_overwrite = true;
$handle->process($_SERVER['DOCUMENT_ROOT'] . '/EduDB/imageUploads/');
if ($handle->processed) {
$handle->clean();
} else {
$_SESSION['ERROR'] = $handle->error;
// Failure
}
}
Identity::updateImage($id, '/EduDB/imageUploads/' . $handle->file_dst_name);
}
header("Location: " . $_POST['path']);
}
示例7: save
function save($id = null, $data)
{
global $osC_Database, $osC_Language, $osC_Image;
if (is_numeric($id)) {
foreach ($osC_Language->getAll() as $l) {
$image_upload = new upload('image' . $l['id'], DIR_FS_CATALOG . 'images/');
if ($image_upload->exists() && $image_upload->parse() && $image_upload->save()) {
$Qdelete = $osC_Database->query('select image from :table_slide_images where image_id = :image_id and language_id=:language_id');
$Qdelete->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
$Qdelete->bindInt(':image_id', $id);
$Qdelete->bindValue(':language_id', $l['id']);
$Qdelete->execute();
if ($Qdelete->numberOfRows() > 0) {
@unlink(DIR_FS_CATALOG . 'images/' . $Qdelete->value('image'));
}
$Qimage = $osC_Database->query('update :table_slide_images set image = :image, description = :description, image_url = :image_url, sort_order = :sort_order, status = :status where image_id = :image_id and language_id=:language_id');
$Qimage->bindValue(':image', $image_upload->filename);
} else {
$Qimage = $osC_Database->query('update :table_slide_images set description = :description, image_url = :image_url, sort_order = :sort_order, status = :status where image_id = :image_id and language_id=:language_id');
}
$Qimage->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
$Qimage->bindValue(':description', $data['description'][$l['id']]);
$Qimage->bindValue(':image_url', $data['image_url'][$l['id']]);
$Qimage->bindValue(':sort_order', $data['sort_order']);
$Qimage->bindValue(':status', $data['status']);
$Qimage->bindInt(':image_id', $id);
$Qimage->bindValue(':language_id', $l['id']);
$Qimage->execute();
}
} else {
$Qmaximage = $osC_Database->query('select max(image_id) as image_id from :table_slide_images');
$Qmaximage->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
$Qmaximage->execute();
$image_id = $Qmaximage->valueInt('image_id') + 1;
foreach ($osC_Language->getAll() as $l) {
$products_image = new upload('image' . $l['id'], DIR_FS_CATALOG . 'images/');
if ($products_image->exists() && $products_image->parse() && $products_image->save()) {
$Qimage = $osC_Database->query('insert into :table_slide_images (image_id,language_id ,description,image ,image_url ,sort_order,status) values (:image_id,:language_id,:description ,:image,:image_url ,:sort_order,:status)');
$Qimage->bindTable(':table_slide_images', TABLE_SLIDE_IMAGES);
$Qimage->bindValue(':image_id', $image_id);
$Qimage->bindValue(':language_id', $l['id']);
$Qimage->bindValue(':description', $data['description'][$l['id']]);
$Qimage->bindValue(':image', $products_image->filename);
$Qimage->bindValue(':image_url', $data['image_url'][$l['id']]);
$Qimage->bindValue(':sort_order', $data['sort_order']);
$Qimage->bindValue(':status', $data['status']);
$Qimage->execute();
}
}
}
if ($osC_Database->isError()) {
return false;
} else {
osC_Cache::clear('slide-images');
return true;
}
}
示例8: storeFileUpload
function storeFileUpload($file, $directory)
{
if (is_writeable($directory)) {
$upload = new upload($file, $directory);
if ($upload->exists() && $upload->parse() && $upload->save()) {
return true;
}
}
return false;
}
示例9: nuevo
public function nuevo()
{
$this->_acl->acceso('Administrador');
$this->_view->assign('titulo', 'Nueva Aplicación');
$this->_view->assign('tipo_app', $this->_aplicacion->getTipoApp());
$this->_view->setJs(array('app'));
if ($this->getInt('guardar') == 1) {
$this->_view->assign('datos', $_POST);
if (!$this->getTexto('nombre')) {
$this->_view->assign('_error', 'Debe introducir nombre');
$this->_view->renderizar('nuevo', 'aplicaciones');
exit;
}
if (!$this->getTexto('descp')) {
$this->_view->assign('_error', 'Debe introducir una descripción');
$this->_view->renderizar('nuevo', 'aplicaciones');
exit;
}
//Agregar demás verificaciones
$imagen = '';
if (isset($_FILES['imagen']['name'])) {
$this->getLibrary('upload' . DS . 'class.upload');
$ruta = ROOT . 'public' . DS . 'img' . DS . 'apps' . DS;
$upload = new upload($_FILES['imagen'], 'es_Es');
$upload->allowed = array('image/*');
$upload->file_new_name_body = 'upl_' . uniqid();
$upload->process($ruta);
if ($upload->processed) {
$imagen = $upload->file_dst_name;
$thumb = new upload($upload->file_dst_pathname);
$thumb->image_resize = true;
$thumb->image_x = 100;
$thumb->image_y = 70;
$thumb->file_name_body_pre = 'thumb_';
$thumb->process($ruta . 'thumb' . DS);
} else {
$this->_view->assign('_error', $upload->error);
$this->_view->renderizar('nuevo', 'aplicaciones');
exit;
}
}
if ($this->_aplicacion->crearApp($_POST['nombre'], $_POST['descp'], $imagen, $_POST['url'], $_POST['host'], $_POST['usu'], $_POST['clave'], $_POST['nom_bd'], $_POST['puerto'], $_POST['tipo'])) {
$this->_view->assign('datos', false);
$this->_view->assign('_confirmacion', 'Conexión exitosa');
$this->_view->renderizar('nuevo', 'aplicaciones');
exit;
} else {
$this->_view->assign('_confirmacion', 'No se realizo la conexión, verifique los datos');
$this->_view->renderizar('nuevo', 'aplicaciones');
exit;
}
}
$this->_view->renderizar('nuevo', 'aplicaciones');
exit;
}
示例10: makeThumb
public function makeThumb()
{
Yii::import('ext.image.class_upload.upload');
$handle = new upload('.'.$this->imgPath.$this->image_name);
$handle->image_resize = true;
$handle->image_ratio_crop = 'T';
$handle->image_x = 72;
$handle->image_y = 72;
$handle->process('.'.$this->thumbPath);
}
示例11: _uploadavatar
public function _uploadavatar()
{
require_once APPLICATION_PATH . "/lib/avataruploader.php";
$inputName = 'uploadfile';
// 即<input type=“file" name="uploadfile" /> 中的name值,不填也行
$upload = new upload($inputName);
$new_dir = INDEX_PATH . '/avatar/';
// 将文件移动到的路径
$upload->moveTo($new_dir);
echo "<img src='/avatar/" . $_SESSION["USERID"] . ".jpg' />";
}
示例12: getOSSToken
public static function getOSSToken()
{
$bucket = Yii::app()->params['partner']['oss']['bucket'];
$domain = Yii::app()->params['partner']['oss']['domain'];
$id = Yii::app()->params['partner']['oss']['id'];
$key = Yii::app()->params['partner']['oss']['key'];
$host = Yii::app()->params['partner']['oss']['host'];
$oss = new upload($id, $key, $domain);
$upToken = $oss->uploadToken($bucket);
return array('uptoken' => $upToken, 'domain' => $domain);
}
示例13: saveAction
public function saveAction()
{
$cid = intval($_POST['wid']);
$name = $_POST['name_cn'];
$name_en = $_POST['name_en'];
$type = $_POST['type'];
$price = $_POST['price'];
$desc = $_POST['desc'];
$year = $_POST['years'];
$active = isset($_POST['active']) && $_POST['active'] == 'on' ? 1 : 0;
if ($cid) {
$sql = "Update \n\t\t\t\t\t\t\t`product` \n\t\t\t\t\t\tset \n\t\t\t\t\t\t\t`name_cn`='" . ms($name) . "',\n\t\t\t\t\t\t\t`name_en`='" . ms($name_en) . "',\n\t\t\t\t\t\t\t`price`='" . intval($price) . "',\n\t\t\t\t\t\t\t`years`=" . intval($year) . ",\n\t\t\t\t\t\t\t`desc`='" . ms($desc) . "',\n\t\t\t\t\t\t\t`type`=" . intval($type) . ",\n\t\t\t\t\t\t\t`active`=" . intval($active) . ",\n\t\t\t\t\t\t\t`modify_time`=" . time() . " \n\t\t\t\t\t\twhere \n\t\t\t\t\t\t\t`id`=" . ms($cid);
} else {
$sql = "Insert into\n\t\t\t\t\t\t\t `product` (\n\t\t\t\t\t\t\t \t\t`name_cn`,\n\t\t\t\t\t\t\t \t\t`name_en`,\n\t\t\t\t\t\t\t \t\t`price`,\n\t\t\t\t\t\t\t \t\t`years`,\n\t\t\t\t\t\t\t \t\t`desc`,\n\t\t\t\t\t\t\t \t\t`type`,\n\t\t\t\t\t\t\t \t\t`active`,\n\t\t\t\t\t\t\t \t\t`modify_time`) \n\t\t\t\t\t\tValues(\n\t\t\t\t\t\t\t'" . ms($name) . "',\n\t\t\t\t\t\t\t'" . ms($name_en) . "',\n\t\t\t\t\t\t\t'" . ms($price) . "',\n\t\t\t\t\t\t\t'" . ms($year) . "',\n\t\t\t\t\t\t\t'" . ms($desc) . "',\n\t\t\t\t\t\t\t'" . ms($type) . "',\n\t\t\t\t\t\t\t'" . ms($active) . "',\n\t\t\t\t\t\t\t" . time() . "\n\t\t\t\t\t\t)";
}
if (DB::query($sql) && !$cid) {
$b_id = DB::lastInsertID();
} else {
if (DB::query($sql) && $cid) {
$b_id = $cid;
}
}
if (!empty($_FILES)) {
$order = 1;
foreach ($_FILES as $i => $v) {
if (!$v['error']) {
$handle1 = new upload($v);
if ($handle1->uploaded) {
$handle1->file_name_body_pre = '16du_';
$handle1->file_new_name_body = $b_id . '_' . $order;
//$handle1->file_new_name_ext = 'png';
$handle1->file_overwrite = true;
$handle1->file_max_size = '40480000';
// $handle1->image_convert = 'png';
//$handle1->png_compression = 5;
$handle1->process(PRODUCT_SRC . $b_id . '/');
if ($handle1->processed) {
$sql = "Update `product` set `src" . $order . "` = '" . $handle1->file_dst_name . "' where `id`=" . $b_id;
DB::query($sql);
$handle1->clean();
} else {
//echo 'error : ' . $handle1->error;
}
$order++;
}
}
}
}
$res = new ResultObj(true, '', '保存成功');
echo $res->toJson();
exit;
}
示例14: get_upload_file
function get_upload_file($fld)
{
global $UploadCache;
if (!isset($UploadCache)) {
$UploadCache = array();
}
if (!isset($UploadCache[$fld])) {
$model_image_obj = new upload($fld);
$model_image_obj->set_destination(DIR_FS_CATALOG_IMAGES);
$UploadCache[$fld] = $model_image_obj->parse() && $model_image_obj->save() ? $model_image_obj->filename : '';
}
//echo 'get_upload_file('.$fld.")=".$UploadCache[$fld]."\n";
return $UploadCache[$fld];
}
示例15: upload
function upload($file)
{
global $_G;
if (!class_exists('upload')) {
include ROOT_PATH . 'web/upload.class.php';
}
if (!is_array($file)) {
$file = $this->file;
}
$upload = new upload();
$img_arr = $attach = array();
$upload_path = '/assets/uploads/';
$rs = $upload->init($file, $upload_path);
if (!$rs) {
return false;
}
$attach =& $upload->attach;
if ($attach['extension'] != 'jpg' && $attach['extension'] != 'png') {
$this->file_type = '.' . $attach['extension'];
$this->__construct();
}
if ($attach['extension'] == 'attach' && $attach['isimage'] != 1) {
$this->msg = '上传的文件非图片';
L($this->msg);
@unlink($attach['tmp_name']);
return false;
//非可上传的文件,就禁止上传了
}
$upload_max_size = $_G['setting']['upload_max_size'] ? intval($_G['setting']['upload_max_size']) : 2;
if ($attach['size'] > 1024 * 1024 * $upload_max_size) {
$this->msg = '上传文件失败,系统设置最大上传大为:' . $upload_max_size . 'MB';
L($this->msg);
@unlink($attach['tmp_name']);
return false;
}
if ($attach['errorcode']) {
$this->msg = '上传图片失败' . errormessage();
@unlink($attach['tmp_name']);
L($this->msg);
return false;
}
$lang_path = ROOT_PATH . $upload_path . $this->dir2;
if (!is_dir($lang_path)) {
dmkdir($lang_path);
}
$attach['target'] = $lang_path . $this->name;
$upload->save();
return $upload_path . $this->dir2 . $this->name;
}