Exemplo n.º 1
0
 /**
  * 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();
 }
Exemplo n.º 2
0
 private function getExceptionData($exception)
 {
     $data = [];
     $data['host'] = Request::server('HTTP_HOST');
     $data['method'] = Request::method();
     $data['fullUrl'] = Request::fullUrl();
     if (php_sapi_name() === 'cli') {
         $data['host'] = parse_url(config('app.url'), PHP_URL_HOST);
         $data['method'] = 'CLI';
     }
     $data['exception'] = $exception->getMessage();
     $data['error'] = $exception->getTraceAsString();
     $data['line'] = $exception->getLine();
     $data['file'] = $exception->getFile();
     $data['class'] = get_class($exception);
     $data['storage'] = array('SERVER' => Request::server(), 'GET' => Request::query(), 'POST' => $_POST, 'FILE' => Request::file(), 'OLD' => Request::hasSession() ? Request::old() : [], 'COOKIE' => Request::cookie(), 'SESSION' => Request::hasSession() ? Session::all() : [], 'HEADERS' => Request::header());
     $data['storage'] = array_filter($data['storage']);
     $count = $this->config['count'];
     $data['exegutor'] = [];
     $data['file_lines'] = [];
     $file = new SplFileObject($data['file']);
     for ($i = -1 * abs($count); $i <= abs($count); $i++) {
         list($line, $exegutorLine) = $this->getLineInfo($file, $data['line'], $i);
         $data['exegutor'][] = $exegutorLine;
         $data['file_lines'][$data['line'] + $i] = $line;
     }
     // to make Symfony exception more readable
     if ($data['class'] == 'Symfony\\Component\\Debug\\Exception\\FatalErrorException') {
         preg_match("~^(.+)' in ~", $data['exception'], $matches);
         if (isset($matches[1])) {
             $data['exception'] = $matches[1];
         }
     }
     return $data;
 }
Exemplo n.º 3
0
 public function sendMail()
 {
     $dets = array('msg' => Request::input('mailDets'), 'subject' => Request::input('subjectH'), 'to' => Request::input('toH'), 'file' => Request::file('file'));
     $rules = array('msg' => 'required', 'subject' => 'required', 'to' => 'required|email');
     $messages = array('msg.required' => 'The email body is required', 'to.required' => 'The recipient\'s address is required', 'to.email' => 'The recepient address is not of the correct format');
     $validator = Validator::make($dets, $rules, $messages);
     if ($validator->fails()) {
         // send back to the page with the input data and errors
         return Redirect::back()->withInput()->withErrors($validator);
     } else {
         //Get the details from the form and send it as an array to the function.
         try {
             Mail::send(array(), array(), function ($message) use($dets) {
                 $message->from('*****@*****.**', 'PaintBuddy Team');
                 $message->to($dets['to']);
                 $message->subject($dets['subject']);
                 $message->setBody($dets['msg'], 'text/html');
                 if (isset($dets['file'])) {
                     $message->attach(Request::file('file'), ['as' => Request::file('file')->getClientOriginalName(), 'mime' => Request::file('file')->getClientOriginalExtension()]);
                 }
             });
         } catch (\Exception $e) {
             throw new SendMailException($e->getMessage());
         }
         if (count(Mail::failures()) > 0) {
             return Redirect::back()->withInput()->withErrors('Mail was not sucessfully sent. Please try again');
         } else {
             return Redirect::back()->with('success', true)->with('message', 'Mail sucessfully sent');
         }
     }
 }
Exemplo n.º 4
0
 /**
  * Add items to the database and the images to 'img/tempEng' directory.
  *
  * @author Sinthujan G.
  * @return mixed Redirects to view with Success or Error messages.
  */
 public function addItems()
 {
     $dets = array('catName' => Request::input('cat_Name'), 'image' => Request::file('image'), 'name' => Request::input('iName'), 'description' => Request::input('iDescrip'), 'size' => Request::input('iSize'), 'price' => Request::input('iPrice'));
     //setting up rules
     $rules = array('image' => 'required|mimes:jpeg,bmp,png', 'name' => 'required', 'description' => 'required', 'size' => 'required', 'price' => 'required|numeric');
     // doing the validation, passing post data, rules and the messages
     $validator = Validator::make($dets, $rules);
     if ($validator->fails()) {
         // send back to the page with the input data and errors
         return Redirect::to('aitem')->withInput()->withErrors($validator);
     } else {
         // checking file is valid.
         if (Request::file('image')->isValid()) {
             $destinationPath = 'img/tempEng';
             $extension = Request::file('image')->getClientOriginalExtension();
             $fileName = rand(11111, 99999) . Carbon::now()->format('Y-m-d') . '.' . $extension;
             Request::file('image')->move($destinationPath, $fileName);
             $res = DB::table('items')->insertGetId(['itName' => $dets['name'], 'itDescrip' => $dets['description'], 'imName' => $fileName, 'itSize' => $dets['size'], 'catRef' => $dets['catName'], 'price' => $dets['price'], 'status' => 'AC']);
             if (!$res) {
                 App::abort(500, 'Some Error');
             }
             return Redirect::to('aitem')->with('success', true)->with('message', 'Item successfully added');
         } else {
             // sending back with error message.
             Session::flash('error', 'uploaded file is not valid');
             App::abort(500, 'Error');
         }
     }
 }
 /**
  * Update an existing model.
  *
  * @param array Data to update a model
  *
  * @return bool
  */
 public function store(array $data)
 {
     if (!empty($data['image']) && $data['image'] == 'delete') {
         $data['image'] = null;
     }
     if (Request::hasFile('image')) {
         $file = FileUpload::handle(Request::file('image'), 'uploads/settings');
         $data['image'] = $file['filename'];
     }
     foreach ($data as $group_name => $array) {
         if (!is_array($array)) {
             $array = [$group_name => $array];
             $group_name = 'config';
         }
         foreach ($array as $key_name => $value) {
             $model = $this->model->where('key_name', $key_name)->where('group_name', $group_name)->first();
             $model = $model ? $model : new $this->model();
             $model->group_name = $group_name;
             $model->key_name = $key_name;
             $model->value = $value;
             $model->save();
         }
     }
     return true;
 }
Exemplo n.º 6
0
 /**
  * Save Image.
  */
 public function saveImages()
 {
     $imageFields = $this->getImageFields();
     $currentUploadDir = $this->getCurrentUploadDir();
     foreach ($imageFields as $imageFieldName => $options) {
         if (array_get($this->attributes, $imageFieldName) instanceof UploadedFile) {
             $file = Request::file($imageFieldName);
             $filename = $file->getClientOriginalName();
             $file->move($this->getThumbnailPath('original'), $filename);
             foreach ($options['thumbnails'] as $thumbnailName => $thumbnailOptions) {
                 $image = Image::make($this->getThumbnailPath('original') . $filename);
                 $resizeType = array_get($thumbnailOptions, 'type', 'crop');
                 switch ($resizeType) {
                     case 'crop':
                         $image->fit($thumbnailOptions['width'], $thumbnailOptions['height']);
                         break;
                     case 'resize':
                         $image->resize($thumbnailOptions['width'], $thumbnailOptions['height'], function ($constraint) {
                             $constraint->aspectRatio();
                         });
                         break;
                 }
                 $thumbnailPath = $this->getThumbnailPath($thumbnailName);
                 if (!File::isDirectory($thumbnailPath)) {
                     File::makeDirectory($thumbnailPath);
                 }
                 $image->save($thumbnailPath . $filename);
             }
             $this->attributes[$imageFieldName] = $filename;
         } elseif ($this->original) {
             $this->attributes[$imageFieldName] = $this->original[$imageFieldName];
         }
     }
 }
Exemplo n.º 7
0
 /**
  * Saves File.
  *
  * @param string $fileName File input name
  * @param string $location Storage location
  *
  * @return array
  */
 public static function saveFile($fileName, $directory = '', $fileTypes = [])
 {
     if (is_object($fileName)) {
         $file = $fileName;
         $originalName = $file->getClientOriginalName();
     } else {
         $file = Request::file($fileName);
         $originalName = false;
     }
     if (is_null($file)) {
         return false;
     }
     if (File::size($file) > Config::get('quarx.maxFileUploadSize', '')) {
         throw new Exception('This file is too large', 1);
     }
     if (substr($directory, 0, -1) != '/') {
         $directory .= '/';
     }
     $extension = $file->getClientOriginalExtension();
     $newFileName = md5(rand(1111, 9999) . time());
     // In case we don't want that file type
     if (!empty($fileTypes)) {
         if (!in_array($extension, $fileTypes)) {
             throw new Exception('Incorrect file type', 1);
         }
     }
     Storage::disk(Config::get('quarx.storage-location', 'local'))->put($directory . $newFileName . '.' . $extension, File::get($file));
     return ['original' => $originalName ?: $file->getFilename() . '.' . $extension, 'name' => $directory . $newFileName . '.' . $extension];
 }
Exemplo n.º 8
0
 public function create(Request $request)
 {
     $file = Request::file('file');
     $randomFilename = str_random();
     $return['fullsize'] = $this->makeImage($file, 1920, 1080, $randomFilename);
     $return['thumbnail'] = $this->makeImage($file, 200, 200, $randomFilename, $return['fullsize']);
     return $return;
 }
Exemplo n.º 9
0
    public function upload()
    {
        if (! Request::hasFile($this->fileFiled)) {
            throw new FileUploadException(100001, '没有该文件');
        }

        $file = Request::file($this->fileFiled);

        if (! $file->isValid()) {
            throw new FileUploadException(100002, '文件上传失败');
        }

        // 获取信息
        $originalName   = $file->getClientOriginalName();
        $mimeType       = $file->getClientMimeType();
        $fileSize       = $file->getClientSize();
        $extension      = strtolower($file->getClientOriginalExtension());

        // 判断后缀
        if (isset($this->config['extensions'])) {
            if (! in_array($extension, $this->config['extensions'])) {
                throw new FileUploadException(100003, '不支持的文件类型');
            }
        }

        // 判断大小
        if (isset($this->config['maxSize'])) {
            if ($fileSize > $this->config['maxSize']) {
                throw new FileUploadExceptions(100004, '文件大小超过最大上传限制');
            }
        }

        // 创建目录结构
        $sub = isset($this->config['subDir']) ? '/' . trim(date($this->config['subDir'], time()), "/\\") . '/' : '/';
        $dir = trim($this->config['rootDir'], "/\\") . $sub;

        // 文件名
        if (isset($this->config['filename'])) {
            $filename = $this->config['filename'];
        } else {
            $filename = time() . str_random(10) . '.' . $extension;
        }

        $file->move($dir, $filename);
        if ($file->getError() != 0) {
            throw new FileUploadException(100005, '移动文件失败');
        }

        return [
            'originalName'  => $originalName,
            'filename'      => $filename,
            'path'          => $dir . $filename,
            'fileSize'      => $fileSize,
            'mimeType'      => $mimeType,
        ];
    }
Exemplo n.º 10
0
 public function image($image, $image_name, $path, $width, $height)
 {
     $name_of_image = $image_name . '.' . Request::file($image)->getClientOriginalExtension();
     Request::file($image)->move(base_path() . $path, $name_of_image);
     $img = Image::make(base_path() . $path . $name_of_image);
     $img->resize($width, $height, function ($constraint) {
         $constraint->aspectRatio();
     });
     return $name_of_image;
 }
Exemplo n.º 11
0
 public function upload($name)
 {
     // Verifying the file
     if (!Request::hasFile($name) || !Request::file($name)->isValid()) {
         return false;
     }
     $this->file = Request::file($name);
     // $this->filesystem->put('docs/file_12_thumb.txt', 'file contents', ['visibility' => 'private']);
     var_dump($this->filesystem->has('docs/file_12_thumb.txt'));
     // var_dump($this->filesystem->delete('docs/file_12_thumb.txt'));
 }
Exemplo n.º 12
0
 /**
  * handle image upload route
  */
 public function image()
 {
     if (Request::hasFile('image') && Request::has('table_name') && Request::has('field_name')) {
         return json_encode(self::saveImage(Request::input('table_name'), Request::input('field_name'), Request::file('image'), null, Request::file('image')->getClientOriginalExtension()));
     } elseif (!Request::hasFile('image')) {
         return 'no image';
     } elseif (!Request::hasFile('table_name')) {
         return 'no table_name';
     } elseif (!Request::hasFile('field_name')) {
         return 'no field_name';
     }
 }
Exemplo n.º 13
0
 /**
  * Save file method.
  */
 public function saveFiles()
 {
     $fileFields = $this->getFileFields();
     foreach ($fileFields as $fieldName => $options) {
         $file = Request::file($fieldName);
         if ($file instanceof UploadedFile && $file->isValid()) {
             $filename = $file->getClientOriginalName();
             $fileSavePath = $this->getFileSavePath($options['dirName']);
             $file->move($fileSavePath, $filename);
             $this->attributes[$fieldName] = $fileSavePath . $filename;
         }
     }
 }
Exemplo n.º 14
0
 public function create(Request $request)
 {
     $file = Request::file('file');
     $randomFilename = str_random();
     $fullsizeWidth = Request::input('full_width', null);
     $fullsizeHeight = Request::input('full_height', null);
     $thumbnailWidth = Request::input('thumb_width', 200);
     $thumbnailHeight = Request::input('thumb_height', 200);
     $overrideDeduplication = Request::input('override_deduplication', 'false');
     $return['fullsize'] = $this->makeImage($file, $fullsizeWidth, $fullsizeHeight, $randomFilename, null, $overrideDeduplication);
     $return['thumbnail'] = $this->makeImage($file, $thumbnailWidth, $thumbnailHeight, $randomFilename, $return['fullsize'], $overrideDeduplication);
     return $return;
 }
Exemplo n.º 15
0
 public function apoyo(Asignacion $request, $id)
 {
     $user = Auth::user()->id;
     $actividad = $this->search($id);
     $file = Request::file('archivo');
     $nombre = $file->getClientOriginalName();
     $extension = $file->getClientOriginalExtension();
     $exists = Storage::disk('local')->exists($nombre);
     if (!$exists) {
         Storage::disk('local')->put($nombre, File::get($file));
         $entry = Apoyo::create(['mime' => $file->getClientMimeType(), 'original_filename' => $file->getClientOriginalName(), 'filename' => $nombre, 'actividad_id' => $id, 'user_id' => $user]);
         $entry->save();
     }
 }
Exemplo n.º 16
0
 public static function uploadPhotos($oImage, $sfile)
 {
     $sDestination = 'images/photos/';
     //$sName =$oImage->getClientOriginalName();
     // dd($sDestination);
     $sDate = date('YmdHis');
     if (Request::file($sfile)->move($sDestination, $sDate . $oImage->getClientOriginalName())) {
         //Asset will give you the directory of public folders, that will be used in saving photos to it!
         //  dd(asset($oImage->getClientOriginalName()));
         return asset($sDestination . $sDate . $oImage->getClientOriginalName());
     } else {
         return false;
     }
 }
Exemplo n.º 17
0
 public function imgUpload()
 {
     //图片最大上传大小
     $maxImgSize = 10485760;
     //允许上传图片类型
     $allowed_extensions = ["png", "jpg"];
     if (!Request::hasFile('file_data')) {
         return response()->json(['errorCode' => 1, 'msg' => '请选择上传文件']);
     }
     $file = Request::file('file_data');
     if ($file->getError() != 0) {
         switch ($file->getError()) {
             case 1:
                 $msg = '上传的文件超过了 php.ini 中 upload_max_filesize 选项限制的值';
                 break;
             case 2:
                 $msg = '上传文件的大小超过了 HTML 表单中 MAX_FILE_SIZE 选项指定的值';
                 break;
             case 3:
                 $msg = '文件只有部分被上传';
                 break;
             case 4:
                 $msg = '没有文件被上传';
                 break;
             case 6:
                 $msg = '找不到临时文件夹';
                 break;
             default:
                 $msg = '文件写入失败';
         }
         return response()->json(['errorCode' => 1, 'msg' => $msg]);
     }
     $img_suffix = $file->getClientOriginalExtension();
     if ($img_suffix && !in_array($img_suffix, $allowed_extensions)) {
         return response()->json(['errorCode' => 1, 'msg' => '请选择png、jpg、jpeg后缀的图片']);
     }
     if ($file->getSize() > $maxImgSize) {
         return response()->json(['errorCode' => 1, 'msg' => '请选择小于10M的图片']);
     }
     $destinationPath = 'uploads/images/';
     $date = date('Ymd');
     if (!file_exists($destinationPath . $date)) {
         mkdir($destinationPath . $date, 0777, true);
     }
     $savePath = $destinationPath . $date . '/';
     $fileName = str_random(15) . '.' . $img_suffix;
     $file->move($savePath, $fileName);
     return response()->json(['errorCode' => 0, 'path' => $savePath . $fileName]);
 }
Exemplo n.º 18
0
 /**
  * @return Response
  */
 public function postIndex()
 {
     if (!Request::hasFile('item_img')) {
         $this->export(50000);
         die;
     }
     $destinationPath = base_path() . '/public/assets/uploads';
     $fileName = md5(microtime()) . '.' . Request::file('item_img')->getClientOriginalExtension();
     $isMoved = Request::file('item_img')->move($destinationPath, $fileName);
     if ($isMoved) {
         $this->export(200, $fileName);
     } else {
         $this->export(50000);
     }
 }
 public function postImage(\Prehistorical\ImageFileLogic\ImageFileLogic $ifl)
 {
     if (Request::hasFile('imagefile') && Request::has('name')) {
         //id - это айди элемента группы, картинки принадлежащие непосредственно блоку проходят с адйди=0
         if (Request::has('id')) {
             $id = Request::input('id');
         } else {
             $id = 0;
         }
         $result = $ifl->storeImage(Request::input('name'), $id, Request::file('imagefile'), false);
         return $result;
     } else {
         return ['status' => 'Не хватает параметров (файла или имени сущности) для сохранения.'];
     }
 }
Exemplo n.º 20
0
 public function register(Request $request)
 {
     $user = $request->session()->get('user');
     $categories = vehicleCategory::all();
     if (isset($request['name']) && !empty($request['name'])) {
         $name = $request['name'];
     }
     if (isset($request['category']) && !empty($request['category'])) {
         $category = $request['category'];
     }
     if (isset($request['models']) && !empty($request['models'])) {
         $models = $request['models'];
     }
     if (isset($request['color']) && !empty($request['color'])) {
         $color = $request['color'];
     }
     if (isset($request['numOfSeats']) && !empty($request['numOfSeats'])) {
         $numOfSeats = $request['numOfSeats'];
     }
     if (isset($request['transmission']) && !empty($request['transmission'])) {
         $transmission = $request['transmission'];
     }
     $uploadMsg = "";
     $fileName = '';
     if (RequestStatic::hasFile('image') && RequestStatic::file('image')->isValid()) {
         $extension = Input::file('image')->getClientOriginalExtension();
         // getting image extension
         $fileName = rand(11111, 99999) . '.' . $extension;
         // renameing image
         $name = $this->destinationPath;
         RequestStatic::file('image')->move($name, $fileName);
     }
     // Retrieve user session
     $user = $request->session()->get('user');
     //Save vehicles for specific user
     $vehicle = new vehicleModel();
     $vehicle->vehicleOwnerID = $user[0]->id;
     $vehicle->vehicleName = $name;
     $vehicle->color = $color;
     $vehicle->numOfSeats = $numOfSeats;
     $vehicle->transmission = $transmission;
     $vehicle->image = $fileName;
     $vehicle->models = $models;
     $vehicle->vehicleCatID = $category;
     $vehicle->save();
     Session::flash('success', 'vehicle successfully registered');
     return Redirect::to('addVehicle');
 }
Exemplo n.º 21
0
 public function register(Request $request)
 {
     $user = $request->session()->get('user');
     $categories = buildingCategory::all();
     if (isset($request['buildingName']) && !empty($request['buildingName'])) {
         $buildingName = $request['buildingName'];
     }
     if (isset($request['lattitude']) && !empty($request['lattitude'])) {
         $lattitude = $request['lattitude'];
     }
     if (isset($request['longitude']) && !empty($request['longitude'])) {
         $longitude = $request['longitude'];
     }
     if (isset($request['category']) && !empty($request['category'])) {
         $category = $request['category'];
     }
     if (isset($request['location']) && !empty($request['location'])) {
         $location = $request['location'];
     }
     if (isset($request['desc']) && !empty($request['desc'])) {
         $desc = $request['desc'];
     }
     $uploadMsg = "";
     $fileName = '';
     if (RequestStatic::hasFile('image') && RequestStatic::file('image')->isValid()) {
         $extension = Input::file('image')->getClientOriginalExtension();
         // getting image extension
         $fileName = rand(11111, 99999) . '.' . $extension;
         // renameing image
         $name = $this->destinationPath;
         RequestStatic::file('image')->move($name, $fileName);
     }
     // Retrieve user session
     $user = $request->session()->get('user');
     //Save building for user
     $building = new buildingModel();
     $building->buildingName = $buildingName;
     $building->lattitude = $lattitude;
     $building->longitude = $longitude;
     $building->buildingLocation = $location;
     $building->buildingCatId = $category;
     $building->landlordID = $user[0]->ID;
     $building->desc = $desc;
     $building->image = $fileName;
     $building->save();
     Session::flash('success', 'Building successfully registered');
     return Redirect::to('addBuilding');
 }
Exemplo n.º 22
0
 public function resetC(Peticion $request, $id)
 {
     $dir = public_path() . '/imagen';
     $users = User::find($id);
     $users->update($request->all());
     $user = Auth::user()->id;
     $file = Request::file('archivo');
     $nombre = $file->getClientOriginalName();
     $ruta = $file->move($dir, $nombre);
     $extension = $file->getClientOriginalExtension();
     $img = ImagenUser::create(['mime' => $file->getClientMimeType(), 'ruta' => $ruta, 'original_img' => $file->getClientOriginalName(), 'img' => $nombre, 'user_id' => $user]);
     $img->save();
     if ($request->ajax()) {
         return response()->json($img);
     }
 }
Exemplo n.º 23
0
 public function importDB()
 {
     //        $file = Request::file('sql')->getRealPath();
     //        return $file;
     $dets = array('sql' => Request::file('sql')->getRealPath());
     //setting up rules
     $rules = array('sql' => 'required');
     // doing the validation, passing post data, rules and the messages
     $validator = Validator::make($dets, $rules);
     if ($validator->fails()) {
         // send back to the page with the input data and errors
         return Redirect::back()->withInput()->withErrors($validator);
     } else {
         Artisan::call('down');
         Artisan::call('db:restore', ['--database' => 'mysql', '--sourcePath' => $dets['sql'], '--compression' => 'null']);
         Artisan::call('up');
         return Redirect::back()->with('success', true)->with('message', 'Item successfully added');
     }
 }
Exemplo n.º 24
0
 /**
  * MDEditor Upload ImgFile
  * @param string $path
  * @return array
  */
 public static function uploadImgFile($path)
 {
     try {
         if (Request::hasFile('editormd-image-file')) {
             $pic = Request::file('editormd-image-file');
             if ($pic->isValid()) {
                 $newName = md5(rand(1, 1000) . $pic->getClientOriginalName()) . "." . $pic->getClientOriginalExtension();
                 $pic->move($path, $newName);
                 $url = asset($path . '/' . $newName);
             } else {
                 self::addError('The file is invalid');
             }
         } else {
             self::addError('Not File');
         }
     } catch (\Exception $e) {
         self::addError($e->getMessage());
     }
     $data = array('success' => !empty($message) ? 0 : 1, 'message' => self::getLastError(), 'url' => !empty($url) ? $url : '');
     return $data;
 }
Exemplo n.º 25
0
 /**
  * On save, upload files.
  *
  * @param Model $model eloquent
  *
  * @return mixed false or void
  */
 public function saving(Model $model)
 {
     if (!($attachments = $model->attachments)) {
         return;
     }
     foreach ($attachments as $fieldname) {
         if (Request::hasFile($fieldname)) {
             // delete prev image
             $file = FileUpload::handle(Request::file($fieldname), 'uploads/' . $model->getTable());
             $model->{$fieldname} = $file['filename'];
             if ($model->getTable() == 'files') {
                 $model->fill($file);
             }
         } else {
             if ($model->{$fieldname} == 'delete') {
                 $model->{$fieldname} = null;
             } else {
                 $model->{$fieldname} = $model->getOriginal($fieldname);
             }
         }
     }
 }
Exemplo n.º 26
0
 public function file(Peticion $request, $id)
 {
     $user = Auth::user()->id;
     $file = Request::file('archivo');
     $nombre = $file->getClientOriginalName();
     $extension = $file->getClientOriginalExtension();
     $exists = Storage::disk('local')->exists($nombre);
     if (!$exists) {
         Storage::disk('local')->put($nombre, File::get($file));
         $entry = Fileentry::create(['mime' => $file->getClientMimeType(), 'original_filename' => $file->getClientOriginalName(), 'filename' => $nombre, 'mensaje' => Input::get('mensaje'), 'usuario' => Input::get('usuario'), 'actividad_id' => $id, 'user_id' => $user]);
         $entry->save();
         return $entry;
     } else {
         if ($exists) {
             $contador = $user + rand(1, 10);
             $modificacion = $nombre . $contador;
             Storage::disk('local')->put($modificacion, File::get($file));
             $change = Fileentry::create(['mime' => $file->getClientMimeType(), 'original_filename' => $modificacion, 'filename' => $modificacion, 'mensaje' => Input::get('mensaje'), 'usuario' => Input::get('usuario'), 'actividad_id' => $id, 'user_id' => $user]);
             $change->save();
             return $change;
         }
     }
 }
 /**
  * Update the specified resource in storage.
  *
  * @param  Request  $request
  * @param  int  $id
  * @return Response
  */
 public function update(UpdateBusiness $request, $id)
 {
     $business = Business::findOrFail($id);
     $logo = Request::file('logo');
     $cover = Request::file('cover');
     $discount_image = Request::file('discount_image');
     $logo_name = $this->storeImage($logo);
     $cover_name = $this->storeImage($cover);
     $discount_image_name = $this->storeImage($discount_image);
     if ($logo_name == null) {
         $logo_name = $business->logo;
     }
     if ($cover_name == null) {
         $cover_name = $business->cover;
     }
     if ($discount_image_name == null) {
         $discount_image_name = $business->discount_image;
     }
     $business->update(['name' => $request->name, 'description' => $request->description, 'logo' => $logo_name, 'cover' => $cover_name, 'discount_image' => $discount_image_name, 'category_id' => $request->category_id, 'email' => $request->email, 'adress' => $request->adress, 'phone' => $request->phone, 'city_id' => $request->city_id, 'zone_id' => $request->zone_id, 'zipcode' => $request->zipcode, 'discount_title' => $request->discount_title, 'discount_price' => $request->discount_price, 'discount_description' => $request->discount_description, 'discount_end_date' => $request->discount_end_date, 'featured' => $request->featured, 'website' => $request->website]);
     return redirect('/admin/business');
 }
Exemplo n.º 28
0
 /**
  *	@author: Arham
  *	@return Request $request
  *  @param: none
  *	desc: assign promotion for user view, add details to database,
  *  check the validations
  *	created : 23/02/2016
  */
 public function setpromotion(Request $request)
 {
     $table1 = null;
     //$titl1 = DB::table('addpromotion')->select('title')->first();
     $pr = 0;
     $oldpromotion = 0;
     $validate = validator::make(input::all(), array('image' => 'mimes:png', 'title' => 'required|min:5', 'body' => 'required|min:10', 'Percentage' => 'required|numeric|min:5|max:50', 'start_date' => 'required|date|after:yesterday', 'end_date' => 'required|date|after:start_date'));
     if ($validate->fails()) {
         return view('pages\\Discount\\assignPromotion', ['pr' => $pr, 'oldpromotion' => $oldpromotion])->withErrors($validate);
     } else {
         $title = Input::get('title');
         $body = Input::get('body');
         $perc = Input::get('Percentage');
         $sdate = Input::get('start_date');
         $edate = Input::get('end_date');
         if (Request::file('image')) {
             $destinationPath = 'images\\promotion';
             // upload path
             $extension = Request::file('image')->getClientOriginalExtension();
             // getting image extension
             $fileName = rand(1, 1) . '.' . $extension;
             //.Carbon::now()->format('Y-m-d');	//set a file name for image
             Request::file('image')->move($destinationPath, $fileName);
             // uploading file to given path
         }
         $pr = DB::table('addpromotion')->insert(array('title' => $title, 'body' => $body, 'ppercentage' => $perc, 'sdate' => $sdate, 'edate' => $edate));
         return View('pages/Discount/assignPromotion', ['pr' => $pr, 'oldpromotion' => $oldpromotion])->withErrors($validate);
     }
 }
Exemplo n.º 29
0
 /**
  * Change the pictures of an item
  *
  * @param  int  $id
  * @param  File $picture1
  * @param  File $picture2
  * @param  bool $dp2
  * @return Response
  */
 public function changePictures()
 {
     $item = Item::find(Request::input('id'));
     // Delete the secondary picture first
     if (Request::has('dp2') && Request::input('dp2') == "true" || Request::file('picture2')) {
         File::delete('uploads/' . $item->hash . '_2.jpg');
         $item->picture2 = false;
     }
     if (Request::file('picture1')) {
         $destination = 'uploads';
         // Give it a unique filename
         $extension = Input::file('picture1')->getClientOriginalExtension();
         if (strtolower($extension) != 'jpg') {
             return Response::make("Please upload only .jpg files.", 400);
         } else {
             $filename = $item->hash . "_1." . strtolower($extension);
             File::delete('uploads/' . $item->hash . '_1.jpg');
             Input::file('picture1')->move($destination, $filename);
         }
     }
     if (Request::file('picture2')) {
         $destination = 'uploads';
         // Give it a unique filename
         $extension = Input::file('picture2')->getClientOriginalExtension();
         if (strtolower($extension) != 'jpg') {
             return Response::make("Please upload only .jpg files.", 400);
         } else {
             $filename = $item->hash . "_2." . strtolower($extension);
             Input::file('picture2')->move($destination, $filename);
         }
         $item->picture2 = true;
     }
     $item->save();
     return Response::make("Success", 205);
 }
Exemplo n.º 30
0
 /**
  * Retrieve a file from the request.
  *
  * @param  string  $key
  * @param  mixed   $default
  * @return \Symfony\Component\HttpFoundation\File\UploadedFile|array
  */
 public function file($key = null, $default = null)
 {
     return parent::file($key, $default);
 }