function file_upload($location, $name) { $storage = new \Upload\Storage\FileSystem($this->basedir . 'img/' . $location, true); $file = new \Upload\File('file', $storage); // Optionally you can rename the file on upload $new_filename = $this->clean_str($name); $file->setName($new_filename); // Validate file upload // MimeType List => http://www.webmaster-toolkit.com/mime-types.shtml $file->addValidations(array(new \Upload\Validation\Mimetype(array('image/png', 'image/bmp', 'image/jpeg', 'image/pjpeg', 'image/gif')), new \Upload\Validation\Size('15M'))); // Access data about the file that has been uploaded $data = array('name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize(), 'md5' => $file->getMd5(), 'dimensions' => $file->getDimensions()); // Try to upload file try { // Success! $file->upload(); return $data; } catch (\Exception $e) { // Fail! $errors = $file->getErrors(); $contex[0] = $e->getFile(); $contex[1] = $e->getLine(); $this->log->addError($e->getMessage(), $contex); } }
public function upload_csv() { $storage = new \Upload\Storage\FileSystem($this->Service->Config()->get_basepath() . '/static/uploads'); $file = new \Upload\File('file', $storage); // Optionally you can rename the file on upload $new_filename = uniqid(); $file->setName($new_filename); // Validate file upload // MimeType List => http://www.webmaster-toolkit.com/mime-types.shtml $file->addValidations(array(new \Upload\Validation\Mimetype(array('text/csv', 'text/plain')), new \Upload\Validation\Size('5M'))); // Access data about the file that has been uploaded $data = array('name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize(), 'md5' => $file->getMd5(), 'dimensions' => $file->getDimensions()); // var_dump($data); // Try to upload file try { // Success! if ($file->upload()) { return $data; } } catch (\Exception $e) { // Fail! $errors = $file->getErrors(); var_dump($errors); } }
public function TestUploadIt() { $req = App::request(); if ($req->isPost()) { echo ROOT; $storage = new \Upload\Storage\FileSystem(ROOT . "/data/v"); $file = new \Upload\File('gfile', $storage); // Optionally you can rename the file on upload $new_filename = uniqid(); $file->setName($new_filename); // Validate file upload // MimeType List => http://www.webmaster-toolkit.com/mime-types.shtml $file->addValidations(array(new \Upload\Validation\Mimetype('video/mp4'), new \Upload\Validation\Size('750M'))); // Access data about the file that has been uploaded $data = array('name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize(), 'md5' => $file->getMd5(), 'dimensions' => $file->getDimensions()); // Try to upload file try { // Success! $file->upload(); } catch (\Exception $e) { // Fail! $errors = $file->getErrors(); var_dump($errors); } echo "just for post"; } else { App::render('/viewku/formupload'); } }
public static function add($formname, $newpath, $newname = '') { $storage = new \Upload\Storage\FileSystem($newpath); $file = new \Upload\File($formname, $storage); // Optionally you can rename the file on upload if ($newname) { $file->setName($newname); } // Validate file upload // MimeType List => http://www.webmaster-toolkit.com/mime-types.shtml $file->addValidations(array(new \Upload\Validation\Mimetype(array('image/png', 'image/gif', 'image/jpeg', 'image/jpeg')), new \Upload\Validation\Size('5M'))); // Try to upload file $errors = ''; try { // Success! $file->upload(); } catch (\Exception $e) { // Fail! $errors = $file->getErrors(); } if ($errors) { return $errors; } else { // Access data about the file that has been uploaded return array('name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize()); } }
protected function uploadFile($field_name) { $storage = new \Upload\Storage\FileSystem(PUBLIC_DIR_UPLOAD); $file = new \Upload\File($field_name, $storage); $file->setName(uniqid()); $file->addValidations(array(new \Upload\Validation\Mimetype(['image/png', 'image/jpeg']), new \Upload\Validation\Size('2M'))); try { $data = array('status' => true, 'name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize(), 'md5' => $file->getMd5(), 'dimensions' => $file->getDimensions()); $file->upload(); } catch (\Exception $e) { $data = ['status' => false, 'message' => $file->getErrors(), 'name' => ""]; } return $data; }
public function bytbildAction($user) { $filter_factory = new \Aura\Filter\FilterFactory(); $filter = $filter_factory->newValueFilter(); //$filter = $filter_factory->newSubjectFilter(); //$vUser = $this->profil->validateInput($user); $vUser = $filter->sanitize($user, 'alnum'); if ($vUser) { $vUser = $user; } else { echo "Användarnamnet är inte alfanumeriskt!"; } $path = ANAX_INSTALL_PATH . '/webroot/files'; $realPath = $this->url->create('files'); $storage = new \Upload\Storage\FileSystem($path); $file = new \Upload\File('profileImage', $storage); // Optionally you can rename the file on upload $new_filename = uniqid(); $file->setName($new_filename); $fileName = $file->getNameWithExtension(); $newPath = $realPath . '/' . $fileName; // Validate file upload // MimeType List => http://www.iana.org/assignments/media-types/media-types.xhtml $file->addValidations(array(new \Upload\Validation\Mimetype(array('image/png', 'image/jpg', 'image/jpeg', 'image/gif')), new \Upload\Validation\Size('5M'))); // Access data about the file that has been uploaded $data = array('name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize(), 'md5' => $file->getMd5(), 'dimensions' => $file->getDimensions()); $this->anvandare->updateImage('anvandare', $vUser, ['username' => $vUser, 'profileimage' => $newPath]); // Try to upload file try { // Success! $file->upload(); $url = $this->url->create('profil/bild') . '/' . $vUser; $this->flash->message('success', 'Bilden uppdaterades'); $output = $this->flash->output(); $userImage = $this->anvandare->findImage($vUser); $this->views->add('profil/profileimage', ['output' => $output, 'userImage' => $userImage]); } catch (\Exception $e) { // Fail! // $errors = $file->getErrors(); $this->flash->message('danger', 'Något gick fel, ladda upp en png eller jpg-fil och försök igen...'); $output = $this->flash->output(); $userImage = $this->anvandare->findImage($vUser); $this->views->add('profil/profileimage', ['output' => $output, 'userImage' => $userImage]); } }
/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { $storage = new \Upload\Storage\FileSystem('../resources/assets/images'); $file = new \Upload\File('image', $storage); $new_filename = uniqid(); $file->setName($new_filename); $file->addValidations(array(new \Upload\Validation\Mimetype('image/jpeg'), new \Upload\Validation\Size('5M'))); $data = array('name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize(), 'md5' => $file->getMd5(), 'dimensions' => $file->getDimensions()); $file->upload(); $book = new Book($request->all()); $book->category_id = $request->all()['categoryId']; $book->unit_id = $request->all()['unitId']; $book->source_id = $request->all()['sourceId']; $book->image = $data['name']; $user = User::find(Auth::id()); $user->books()->save($book); return redirect(route('admin.books.show', $book->id)); }
if (!file_exists($cfgFile)) { err(500, "Configuration file does not exist.", "Copy data/surrogator.config.php.dist to data/surrogator.config.php"); exit(2); } } require $cfgFile; require __DIR__ . '/shib_attr.php'; $storage = new \Upload\Storage\FileSystem($rawDir, true); $file = new \Upload\File('profileFile', $storage); // Optionally you can rename the file on upload $mail = strtolower($shib_mail); $file->setName($mail); // Validate file upload // MimeType List => http://www.iana.org/assignments/media-types/media-types.xhtml $file->addValidations(array(new \Upload\Validation\Mimetype(array('image/png', 'image/jpeg')), new \Upload\Validation\Size('5M'))); // Access data about the file that has been uploaded $data = array('name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize(), 'md5' => $file->getMd5(), 'dimensions' => $file->getDimensions()); // Try to upload file try { // Success! shell_exec('rm ' . __DIR__ . '/../raw/' . $mail . '.*'); $file->upload(); $output = shell_exec('php ' . __DIR__ . '/../surrogator.php'); $results = array('status' => 'ok', 'file_data' => $data, 'surroggator' => $output); echo json_encode($results); } catch (\Exception $e) { // Fail! $errors = $file->getErrors(); $results = array('status' => 'error', 'error' => $errors); echo json_encode($results); }
use Upload\Storage; $app->get('/upload', function () use($app) { $app->render('test/upload.php'); })->name('test.upload'); $app->post('/upload', function () use($app) { $storage = new \Upload\Storage\FileSystem(INC_ROOT . '/images/user/icon'); $file = new \Upload\File('prof_pic', $storage); // Optionally you can rename the file on upload // Setting a randomly generated name - could be userful if it is stored in the database // $new_filename = uniqid(); // check if the user already has an image, $file->setName($app->auth->username); // Validate file upload // MimeType List => http://www.iana.org/assignments/media-types/media-types.xhtml $file->addValidations(array(new \Upload\Validation\Mimetype(array('image/png', 'image/jpg', 'image/jpeg')), new \Upload\Validation\Size('500K'))); // Access data about the file that has been uploaded $data = array('name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize()); // Try to upload file try { // Success! $file->upload(); } catch (\Exception $e) { // Fail! $errors = $file->getErrors(); $app->flash('global', 'Rip that image'); return $app->render('test/upload.php', ['errors' => $errors]); } $app->flash('global', 'Upload was successful'); return $app->response->redirect($app->urlFor('home')); })->name('test.upload.post');
/** * [article_update 更新文章] * @return [type] [description] */ public function article_update($slug) { if (IS_POST) { //实例化上传类 $storage = new \Upload\Storage\FileSystem(__UPLOAD__); $file = new \Upload\File('foo', $storage); $fileName = $file->getNameWithExtension(); if (!empty($fileName)) { // Optionally you can rename the file on upload $new_filename = uniqid(); $file->setName($new_filename); // Validate file upload // MimeType List => http://www.webmaster-toolkit.com/mime-types.shtml $file->addValidations([new \Upload\Validation\Mimetype(['image/png', 'image/gif', 'image/jpeg', 'image/jpg']), new \Upload\Validation\Size('5M')]); // Access data about the file that has been uploaded $data = ['name' => $file->getNameWithExtension(), 'extension' => $file->getExtension(), 'mime' => $file->getMimetype(), 'size' => $file->getSize(), 'md5' => $file->getMd5(), 'dimensions' => $file->getDimensions()]; // Try to upload file try { // Success! $file->upload(); $arcData = ['title' => I('post.title'), 'thumb' => $data['name'], 'keywords' => I('post.keywords'), 'content' => I('post.content'), 'description' => I('post.description'), 'category_id' => I('post.category_id'), 'click' => I('post.click'), 'writer' => I('post.writer'), 'source' => I('post.source'), 'pubdate' => time()]; Article::where(['id' => $slug])->update($arcData); View::success('修改成功'); die; } catch (\Exception $e) { // Fail! $errors = $file->getErrors(); View::error($errors['0']); die; } } if (isset($_POST['del_img'])) { $arcData = ['title' => I('post.title'), 'keywords' => I('post.keywords'), 'thumb' => '', 'content' => I('post.content'), 'description' => I('post.description'), 'category_id' => I('post.category_id'), 'click' => I('post.click'), 'writer' => I('post.writer'), 'source' => I('post.source'), 'pubdate' => time()]; Article::where(['id' => $slug])->update($arcData); View::success('修改成功'); die; } else { $arcData = ['title' => I('post.title'), 'keywords' => I('post.keywords'), 'content' => I('post.content'), 'category_id' => I('post.category_id'), 'click' => I('post.click'), 'writer' => I('post.writer'), 'source' => I('post.source'), 'pubdate' => time()]; Article::where(['id' => $slug])->update($arcData); View::success('修改成功'); die; } } $arcData = Article::find($slug)->toArray(); //print_r($arcData); $topcate = Category::where(['pid' => 0, 'is_del' => 0])->get()->toArray(); //组合分类数据 foreach ($topcate as $k => $v) { $soncate = Category::where(['pid' => $v['id'], 'is_del' => 0])->get()->toArray(); $topcate[$k]['soncate'] = $soncate; } $allcate = $topcate; $this->smarty->assign('title', '修改文章_ISisWeb中文网后台管理_ISirPHPFramework'); $this->smarty->assign('cate', $allcate); $this->smarty->assign('arcData', $arcData); $this->smarty->display('Admin/Article/update.html'); // die(); // $this->view = View::make('/Admin/Article/update') // ->with('cate',$allcate) // ->with('arcData',$arcData) // ->with('title','修改文章_ISirWeb中文网后台'); }