Пример #1
0
 /**
  * Start a big file download on Laravel Framework 4.0 / 4.1
  * Source (originally for Laravel 3.*) : http://stackoverflow.com/questions/15942497/why-dont-large-files-download-easily-in-laravel
  * @param  string $path    Path to the big file
  * @param  string $name    Name of the file (used in Content-disposition header)
  * @param  array  $headers Some extra headers
  */
 public function sendFile($path, $name = null, array $headers = array())
 {
     if (is_null($name)) {
         $name = basename($path);
     }
     $file = new \Symfony\Component\HttpFoundation\File\File($path);
     $mime = $file->getMimeType();
     // Prepare the headers
     $headers = array_merge(array('Content-Description' => 'File Transfer', 'Content-Type' => $mime, 'Content-Transfer-Encoding' => 'binary', 'Expires' => 0, 'Cache-Control' => 'must-revalidate, post-check=0, pre-check=0', 'Pragma' => 'public', 'Content-Length' => \File::size($path), 'Content-Disposition' => 'attachment; filename=' . $name), $headers);
     $response = new \Symfony\Component\HttpFoundation\Response('', 200, $headers);
     // If there's a session we should save it now
     if (\Config::get('session.driver') !== '') {
         \Session::save();
     }
     session_write_close();
     if (ob_get_length()) {
         ob_end_clean();
     }
     $response->sendHeaders();
     // Read the file
     if ($file = fopen($path, 'rb')) {
         while (!feof($file) and connection_status() == 0) {
             print fread($file, 1024 * 8);
             flush();
         }
         fclose($file);
     }
     // Finish off, like Laravel would
     \Event::fire('laravel.done', array($response));
     $response->send();
 }
 /**
  * Display a listing of the resource.
  *
  * @return Response
  */
 public function getVideo($classname, $instructorname, $filename)
 {
     $path = \Config::get('res.up-videos') . '/' . $classname . '/' . $instructorname . '/' . $filename;
     $file = new \Symfony\Component\HttpFoundation\File\File($path);
     $response = \Response::make(\File::get($path), 200);
     $response->header('Content-type', $file->getMimeType());
     //return the video
     return $response;
 }
 public function getDescargar($foto_id)
 {
     $foto = FotoSolicitud::findOrFail($foto_id);
     $path = storage_path('adjuntos' . DIRECTORY_SEPARATOR . $foto->solicitud_id . DIRECTORY_SEPARATOR . $foto->foto);
     $length = filesize($path);
     $file = new Symfony\Component\HttpFoundation\File\File($path);
     $headers = array('Content-Disposition' => 'inline; filename="' . $foto->foto . '"', 'Content-Type' => $file->getMimeType(), 'Content-Length' => $length);
     return Response::make(File::get($path), 200, $headers);
 }
Пример #4
0
 /**
  * @param string $filename
  * @return string mimetype
  */
 public function getMimeType($filename)
 {
     // Make the input file path.
     $inputDir = Config::get('assets.images.paths.input');
     $inputFile = $inputDir . '/' . $filename;
     // Get the file mimetype using the Symfony File class.
     $file = new \Symfony\Component\HttpFoundation\File\File($inputFile);
     return $file->getMimeType();
 }
Пример #5
0
 public function getUploads($url = "")
 {
     dd($url);
     //TODO: security on this file.
     $filename = base_path() . '/uploads/' . $url;
     $file = File::get($filename);
     $fileData = new \Symfony\Component\HttpFoundation\File\File($filename);
     $response = Response::make($file, 200);
     $response->headers->set('Content-Type', $fileData->getMimeType());
     return $response;
 }
 public static function showCandidateImage($info)
 {
     //$path = storage_path('myimages') . '/' . $img;
     $info = CandidateInfo::find($info);
     $path = storage_path($info->photo_url);
     $handler = new \Symfony\Component\HttpFoundation\File\File($path);
     $lifetime = 31556926;
     /**
      * Prepare some header variables
      */
     $file_time = $handler->getMTime();
     // Get the last modified time for the file (Unix timestamp)
     $header_content_type = $handler->getMimeType();
     $header_content_length = $handler->getSize();
     $header_etag = md5($file_time . $path);
     $header_last_modified = gmdate('r', $file_time);
     $header_expires = gmdate('r', $file_time + $lifetime);
     $headers = array('Content-Disposition' => 'inline; filename="' . $info->photo_url . '"', 'Last-Modified' => $header_last_modified, 'Cache-Control' => 'must-revalidate', 'Expires' => $header_expires, 'Pragma' => 'public', 'Etag' => $header_etag);
     /** Is the resource cached? */
     $h1 = isset($_SERVER['HTTP_IF_MODIFIED_SINCE']) && $_SERVER['HTTP_IF_MODIFIED_SINCE'] == $header_last_modified;
     $h2 = isset($_SERVER['HTTP_IF_NONE_MATCH']) && str_replace('"', '', stripslashes($_SERVER['HTTP_IF_NONE_MATCH'])) == $header_etag;
     if ($h1 || $h2) {
         return Response::make('', 304, $headers);
         // File (image) is cached by the browser, so we don't have to send it again
     }
     $headers = array_merge($headers, array('Content-Type' => $header_content_type, 'Content-Length' => $header_content_length));
     return Response::make(file_get_contents($path), 200, $headers);
 }
 protected function _saveFileFromExistingPath($model)
 {
     $fileParts = explode('.', $model->path);
     $ext = end($fileParts);
     $destinationPath = $model->getFullPathToFolder();
     $filename = str_random(16) . (strlen($ext) > 5 ? '' : '.' . $ext);
     $filePath = $destinationPath . '/' . $filename;
     @file_put_contents($filePath, @file_get_contents($model->path));
     if (file_exists($filePath)) {
         $file = new \Symfony\Component\HttpFoundation\File\File($filePath);
         $model->mimetype = $file->getMimeType();
         $model->filename = $filename;
     }
     unset($model->path);
     $this->_saveModel($model, $filename);
 }
Пример #8
0
 public function show()
 {
     $id = Session::remove("blinkId");
     if ($id != null) {
         $blink = Blink::find($id);
         $blink->time_viewed;
         if ($blink != null && $blink->view_time > $blink->time_viewed) {
             $path = $blink->file_location;
             $file = new Symfony\Component\HttpFoundation\File\File($path);
             $response = Response::make(File::get($path), 200);
             // Modify our output's header.
             // Set the content type to the mime of the file.
             // In the case of a .jpeg this would be image/jpeg
             $response->header('Content-type', $file->getMimeType());
             // We return our image here.
             return $response;
         }
     }
 }
Пример #9
0
 public function resize($id, $size = null)
 {
     $asset = Asset::find($id);
     if ($asset == null) {
         return '';
     }
     $url = $asset->relativeURL();
     $w = null;
     $h = null;
     $s = null;
     if ($size != null) {
         preg_match('/w(\\d+)/', $size, $wMatch);
         preg_match('/h(\\d+)/', $size, $hMatch);
         preg_match('/s(\\d+)/', $size, $sMatch);
         if (count($wMatch) >= 2) {
             $w = $wMatch[1];
         }
         if (count($hMatch) >= 2) {
             $h = $hMatch[1];
         }
         if (count($sMatch) >= 2) {
             $s = $sMatch[1];
         }
     }
     $img = Image::cache(function ($image) use($url, $w, $h, $s) {
         $image->make($url);
         if ($s != null) {
             $image->resize($s, null, function ($constraint) {
                 $constraint->aspectRatio();
             })->crop($s, $s);
         } else {
             if ($w != null || $h != null) {
                 $image->resize($w, $h, function ($constraint) {
                     $constraint->aspectRatio();
                 });
             }
         }
         return $image;
     });
     $file = new \Symfony\Component\HttpFoundation\File\File($url);
     $mime = $file->getMimeType();
     return Response::make($img, 200, array('Content-Type' => $mime));
 }
 /**
  * Attempt to detect mime type for given file
  *
  * @param string $path
  * @return string Mime type if found
  */
 protected static function get_mime($path)
 {
     $file = new Symfony\Component\HttpFoundation\File\File($path);
     return $file->getMimeType();
 }
Пример #11
0
 /**
  * @ORM\PostPersist()
  * @ORM\PostUpdate()
  */
 public function upload()
 {
     if (null === $this->tmpPath) {
         return;
     }
     $fileName = explode('/', $this->tmpPath);
     $fileName = $fileName[count($fileName) - 1];
     $file = new \Symfony\Component\HttpFoundation\File\File($this->tmpPath);
     $file->move($this->getUploadRootDir(), $this->path);
 }
Пример #12
0
 public static function missingImageResponse()
 {
     $temp = Asset::missingFile();
     $missingFile = new \Symfony\Component\HttpFoundation\File\File($temp->getMissingImage());
     $mimeType = $missingFile->getMimeType();
     if ($missingFile->getMimeType() == 'text/plain') {
         $mimeType = 'image/svg+xml';
     }
     return Response::make(File::get($temp->getMissingImage()), 200, array('Content-Type' => $mimeType));
 }
Пример #13
0
 public function resizeImage($id, $size = null)
 {
     $asset = is_object($id) ? $id : $this->find($id);
     if ($asset == null) {
         return $this->missingImageResponse();
     }
     if ($asset->isImage() == false && $asset->isSVG() == false) {
         return 'Error: Wrong File Format';
     }
     $url = $asset->relativeURL();
     $params = $this->parseSizeFromString($size);
     // if we are svg just return the file
     // todo: parse svg and alter width/height
     if ($asset->isSVG()) {
         $svgFile = File::get($url);
         if ($params->s != null) {
             if ($params->retina) {
                 $params->s *= 2;
             }
             $svgFile = $this->resizeSVG($svgFile, $params->s, null);
         } else {
             if ($params->w != null || $params->h != null) {
                 if ($params->retina) {
                     if ($params->w != null) {
                         $params->w *= 2;
                     }
                     if ($params->h != null) {
                         $params->h *= 2;
                     }
                 }
                 $svgFile = $this->resizeSVG($svgFile, $params->w, $params->h);
             }
         }
         if ($params->raw) {
             $str = strpos($svgFile, "<svg") ? substr($svgFile, strpos($svgFile, "<svg")) : $svgFile;
             return Response::make($str, 200, array('Content-Type' => 'image/svg+xml'));
         }
         return Response::make($svgFile, 200, array('Content-Type' => 'image/svg+xml'));
     }
     $info = pathinfo($url);
     $basename = str_until($size, ".");
     $filename = $size ? $info['filename'] . '_' . $basename . '.' . $info['extension'] : $info['filename'] . '.' . $info['extension'];
     $path = $info['dirname'] . '/' . $filename;
     if (File::exists($path)) {
         $file = new \Symfony\Component\HttpFoundation\File\File($path);
         $mime = $file->getMimeType();
         return Response::make(File::get($path), 200, array('Content-Type' => $mime));
     }
     $img = Image::cache(function ($image) use($url, $params, $path) {
         $image->make($url);
         if ($params->s != null) {
             if ($params->retina) {
                 $params->s *= 2;
             }
             $image->fit($params->s, $params->s)->sharpen(3);
             /*
             				$image->resize($desw, $desh, function ($constraint) {
                 				$constraint->aspectRatio();
             				})->crop($s, $s);*/
         } else {
             if ($params->w != null || $params->h != null) {
                 if ($params->retina) {
                     if ($params->w != null) {
                         $params->w *= 2;
                     }
                     if ($params->h != null) {
                         $params->h *= 2;
                     }
                 }
                 $image->resize($params->w, $params->h, function ($constraint) {
                     $constraint->aspectRatio();
                 });
             }
         }
         $image->save($path);
         return $image;
     });
     $file = new \Symfony\Component\HttpFoundation\File\File($url);
     $mime = $file->getMimeType();
     return Response::make($img, 200, array('Content-Type' => $mime));
 }
Пример #14
0
 /**
  * Displays the default view page
  *
  * @access public
  * @param  string  $urlkey
  * @param  string  $hash
  * @param  string  $action
  * @param  string  $extra
  * @return \Illuminate\Support\Facades\View|\Illuminate\Support\Facades\Redirect|null
  */
 public function getPaste($urlkey, $hash = '', $action = '', $extra = '')
 {
     $site = Site::config('general');
     $paste = Paste::where('urlkey', $urlkey)->first();
     // Paste was not found
     if (is_null($paste)) {
         App::abort(404);
         // Not found
     }
     // Check if the logged in user is the owner of the paste
     $owner = Auth::access($paste->author_id);
     // We do not make password prompt mandatory for owners
     if (!$owner) {
         // Require hash to be passed for private pastes
         if ($paste->private and $paste->hash != $hash) {
             App::abort(401);
             // Unauthorized
         }
         // Check if paste is password protected and user hasn't entered
         // the password yet
         if ($paste->password and !Session::has('paste.password' . $paste->id)) {
             return View::make('site/password', array());
         }
     }
     // Increment the hit counter
     if (!Session::has('paste.viewed' . $paste->id)) {
         $paste->hits++;
         $paste->save();
         Session::put('paste.viewed' . $paste->id, TRUE);
     }
     // Let's do some action!
     switch ($action) {
         case 'delete':
             if (empty($extra)) {
                 // Delete the paste if the user has access
                 if ($site->allowPasteDel and $owner) {
                     Revision::where('urlkey', $paste->urlkey)->delete();
                     $paste->comments()->delete();
                     $attachment = storage_path() . "/uploads/{$paste->urlkey}";
                     if ($paste->attachment and File::exists($attachment)) {
                         File::delete($attachment);
                     }
                     $paste->delete();
                     Session::flash('messages.success', Lang::get('global.paste_deleted'));
                     return Redirect::to('/');
                 } else {
                     App::abort(401);
                     // Unauthorized
                 }
             } else {
                 if (is_numeric($extra)) {
                     $comment = Comment::findOrFail($extra);
                     // Delete the comment if the user has access
                     if ($owner or Auth::user()->username == $comment->author) {
                         $comment->delete();
                     } else {
                         App::abort(401);
                         // Unauthorized
                     }
                 }
             }
             return Redirect::to(URL::previous());
         case 'raw':
             $response = Response::make($paste->data);
             $response->header('Content-Type', 'text/plain');
             return $response;
         case 'toggle':
             if ($owner) {
                 Revision::where('urlkey', $paste->urlkey)->delete();
                 $paste->private = $paste->private ? 0 : 1;
                 $paste->password = '';
                 $paste->save();
             }
             return Redirect::to(URL::previous());
         case 'flag':
             if ($site->flagPaste == 'all' or $site->flagPaste == 'user' and Auth::roles()->user) {
                 $paste->flagged = 1;
                 $paste->save();
                 Cache::forget('global.flags');
                 Session::flash('messages.success', Lang::get('global.paste_flagged'));
             } else {
                 App::abort(401);
                 // Unauthorized
             }
             return Redirect::to(URL::previous());
         case 'unflag':
             if (Auth::roles()->admin) {
                 $paste->flagged = 0;
                 $paste->save();
                 Cache::forget('global.flags');
                 Session::flash('messages.success', Lang::get('global.paste_unflagged'));
             } else {
                 App::abort(401);
                 // Unauthorized
             }
             return Redirect::to(URL::previous());
     }
     // Build the sharing subject for the paste
     $subject = sprintf(Lang::get('mail.share_subject'), $site->title, URL::current());
     // Build data for show paste page
     $data = array('paste' => $paste, 'revisions' => $paste->revisions, 'comments' => $paste->comments()->paginate($site->perPage), 'share' => 'mailto:?subject=' . urlencode($subject), 'attachment' => sprintf(Lang::get('show.download_attachment'), Lang::get('show.unknown')));
     // If paste has an attachment, get the file type
     if ($paste->attachment) {
         $pathToFile = storage_path() . "/uploads/{$paste->urlkey}";
         if (File::exists($pathToFile)) {
             $file = new Symfony\Component\HttpFoundation\File\File($pathToFile);
             $data['attachment'] = sprintf(Lang::get('show.download_attachment'), $file->getMimeType());
         }
     }
     // Display the show paste view
     return View::make('site/show', $data);
 }
Пример #15
0
 public function postUpload($sid)
 {
     $media = Media::find($sid);
     if ($media == null) {
         die('{"OK": 0, "info": "Unable to find this media record in the database. It could have been deleted."}');
     }
     $media_tmp_folder = public_path() . '/assets/medias/tmp/' . $media->category_id . '/' . $sid;
     $media_folder = public_path() . '/assets/medias/' . $media->category_id . '/' . $sid;
     if (empty($_FILES) || $_FILES['file']['error']) {
         die('{"OK": 0, "info": "Failed to move uploaded file."}');
     }
     $chunk = isset($_REQUEST["chunk"]) ? intval($_REQUEST["chunk"]) : 0;
     $chunks = isset($_REQUEST["chunks"]) ? intval($_REQUEST["chunks"]) : 0;
     $fileName = isset($_REQUEST["name"]) ? $_REQUEST["name"] : $_FILES["file"]["name"];
     //$filePath = public_path() . '/assets/medias' . "/$fileName";
     $filePath = $media_tmp_folder . "/{$fileName}";
     // Create the directory
     if (!file_exists($media_tmp_folder)) {
         mkdir($media_tmp_folder, 0777, true);
     }
     // For Unit testing
     if ($fileName == 'foo113a.pdf') {
         die('{"OK": 1, "info": "Upload successful."}');
     }
     // Open temp file
     $out = @fopen("{$filePath}.part", $chunk == 0 ? "wb" : "ab");
     if ($out) {
         // Read binary input stream and append it to temp file
         $sin = @fopen($_FILES['file']['tmp_name'], "rb");
         if ($sin) {
             while ($buff = fread($sin, 4096)) {
                 fwrite($out, $buff);
             }
         } else {
             die('{"OK": 0, "info": "Failed to open input stream."}');
         }
         @fclose($sin);
         @fclose($out);
         @unlink($_FILES['file']['tmp_name']);
     } else {
         die('{"OK": 0, "info": "Failed to open output stream."}');
     }
     // Check if file has been uploaded
     if (!$chunks || $chunk == $chunks - 1) {
         // Strip the temp .part suffix off
         rename("{$filePath}.part", $filePath);
         // Get mime type of the file
         $file = new \Symfony\Component\HttpFoundation\File\File($filePath);
         $mime = $file->getMimeType();
         // Save the media link
         $media->path = $fileName;
         $media->mimetype = $mime;
         $media->options = json_encode($this->retrieveId3Info($file));
         $media->save();
         $deleteFolder = new Image();
         // Delete old media
         $deleteFolder->deleteFiles($media_folder);
         // Create the directory
         if (!file_exists($media_folder)) {
             mkdir($media_folder, 0777, true);
         }
         \File::move($filePath, $media_folder . "/{$fileName}");
         // Delete tmp media
         $deleteFolder->deleteFiles($media_tmp_folder);
     }
     die('{"OK": 1, "info": "Upload successful."}');
 }
Пример #16
0
 public function getMimeType()
 {
     $file = new \Symfony\Component\HttpFoundation\File\File($this->relativeURL());
     return $file->getMimeType();
 }
Пример #17
0
    }));
    Route::any(config('bootlegcms.cms_route') . 'login', array('uses' => 'Bootleg\\Cms\\UsersController@anyLogin'));
    Route::group(array('prefix' => config('bootlegcms.cms_route')), function () use($locale) {
        Route::group(array('prefix' => $locale), function () {
            Route::any('/', array('uses' => 'Bootleg\\Cms\\UsersController@anyDashboard'));
            Route::controller('content', 'Bootleg\\Cms\\ContentsController');
            Route::controller('template', 'Bootleg\\Cms\\TemplateController');
            Route::controller('application', 'Bootleg\\Cms\\ApplicationController');
            Route::controller('users', 'Bootleg\\Cms\\UsersController');
            Route::controller('reminders', 'Bootleg\\Cms\\RemindersController');
        });
    });
    Route::pattern('upl', '(.*)');
    Route::get('/uploads/{upl?}', function ($filename = null) {
        //TODO: security on this file.
        //$filename = stripslashes(str_replace('/','',$filename));
        $filename = storage_path() . '/uploads/' . $filename;
        $file = File::get($filename);
        $fileData = new \Symfony\Component\HttpFoundation\File\File($filename);
        $response = Response::make($file, 200);
        $response->headers->set('Content-Type', $fileData->getMimeType());
        return $response;
    });
    Route::any('/{slug?}', function ($slug = '/') use($application, $applicationurl) {
        //TODO: we should really move this into PageController at some point.
        return Bootleg\Cms\PageController::page($slug, $application, $applicationurl);
    })->where('slug', '(.*)');
    //});
    \Event::fire('routes.after');
    //    Route::controller('/', 'PageController');
});
Пример #18
0
        </div>
    </div>


    <div class="list-group">
        @foreach($files as $file)
        <div class="list-group-item well">
            <div class="row-action-primary">
                @php
                $ext = \App\Jen\JenCat::getFileExtension($file->file_name);
                @endphp
                <img src="/assets/fti/{{$ext}}.png" alt="{{$ext}}"/>
            </div>
            <div class="row-content" style="width:100% !important;">
                <?php 
$f = new Symfony\Component\HttpFoundation\File\File($file->path);
$mime = $f->getMimeType();
?>
                <h4 class="list-group-item-heading">{{$file->file_name}}</h4>
                <div>

                    @if(strpos($mime, "audio") !== false || \App\Jen\JenCat::getFileExtension($file->file_name) == "mp3")
                        <audio controls src="/files/download/{{$file->access_token}}"></audio>
                    @endif
                </div>
                <span class="u-pull-left"><a title="{{trans('files.download')}}" href="/files/download/{{$file->access_token}}" class="btn btn-sm btn-flat btn-info"><i class="material-icons">cloud_download</i></a></span>
                @if($file->user_id == session()->get('uid'))
                <span class="u-pull-right"><a title="{{trans('files.share')}}" href="javascript:void(0);" onclick="makePublic({{$file->id}})" class="btn btn-sm btn-flat btn-primary"><i class="material-icons" id="icon{{$file->id}}">{{$file->public == 0 ? "lock_outline" : "lock_open"}}</i> <span style="display: none;" id="text{{$file->id}}">{{$file->public == 0 ? "Open" : "Close"}}</span></a></span>
                <span class="u-pull-right"><a title="{{trans('files.delete')}}" href="javascript:void(0);" onclick="deleteFile({{$file->id}})" class="btn btn-sm btn-flat btn-danger"><i class="material-icons">delete</i></a></span>