mimeType() public static method

Get the mime-type of a given file.
public static mimeType ( string $path ) : string | false
$path string
return string | false
Route::group(array('module' => 'Supplier', 'namespace' => 'Supplier\\Controllers'), function () {
    Route::resource('/supplier/login', 'SupplierController@login');
    Route::resource('/supplier/register', 'SupplierController@register');
    Route::resource('/supplier/logout', 'SupplierController@logout');
    Route::post('/userAjaxHandler', 'SupplierController@userAjaxHandler');
    //IF  YOU NEED TO USE GET POST, USE THIS FORMAT AS IN BELOW BLOCK COMMENT
    /*Route::get('admin/dashboard', function () {
          return view("Admin/Views/dashboard");
      }); */
    Route::group(['middleware' => 'auth:supplier'], function () {
        //        Supplier Controller
        Route::resource('/supplier/dashboard', 'SupplierController@dashboard');
        Route::resource('/supplier/profile', 'SupplierController@profile');
        Route::resource('/supplier/supplierDetails', 'SupplierController@supplierDetails');
        Route::post('/supplier/ajaxHandler', 'SupplierController@ajaxHandler');
        Route::get('images/{filename}', function ($filename) {
            //            die($filename);
            $fileInfo = explode("_", $filename);
            $path = storage_path() . '/uploads/' . $fileInfo[0] . '/' . $filename;
            //            die($path);
            $file = File::get($path);
            $type = File::mimeType($path);
            $response = Response::make($file, 200);
            $response->header("Content-Type", $type);
            return $response;
            //            Route::get('images/{filename}', 'SupplierController@getImages');
        });
        //        Product Controller
        Route::resource('/supplier/add-product', 'ProductController@addProduct');
    });
});
Example #2
0
    return ['code' => strtoupper($faker->bothify('??##??#?')), 'style' => rand(0, 4) ? ucwords(join(' ', $faker->words(rand(1, 4)))) : '', 'description' => $faker->paragraph, 'specs' => collect($specs)];
});
$factory->define(App\File::class, function (Faker\Generator $faker) {
    $generated = $faker->file('/tmp', storage_path());
    $filename = \File::name($generated) . '.pdf';
    $filepath = public_path() . '/files/' . $filename;
    $saved = \File::move($generated, $filepath);
    return ['path' => 'files/' . $filename, 'mime' => \File::mimeType($filepath), 'extension' => \File::extension($filepath), 'size' => \File::size($filepath)];
});
$factory->define(App\SafetyDataSheet::class, function (Faker\Generator $faker) {
    return ['title' => ucwords(join(' ', $faker->words(rand(1, 4))))];
});
$factory->define(App\DataSheet::class, function (Faker\Generator $faker) {
    return ['title' => ucwords(join(' ', $faker->words(rand(1, 4))))];
});
$factory->define(App\Brochure::class, function (Faker\Generator $faker) {
    return ['title' => ucwords(join(' ', $faker->words(rand(1, 4))))];
});
$factory->define(App\Image::class, function (Faker\Generator $faker) {
    $file = new App\File();
    $generated = $faker->image('/tmp', 1024, 768);
    $filename = \File::name($generated) . '.' . \File::extension($generated);
    $filepath = public_path() . '/files/' . $filename;
    $saved = \File::move($generated, $filepath);
    $fileEntity = App\File::create(['path' => 'files/' . $filename, 'mime' => \File::mimeType($filepath), 'extension' => \File::extension($filepath), 'size' => \File::size($filepath)]);
    return ['title' => ucwords(join(' ', $faker->words(rand(1, 4)))), 'file_id' => $fileEntity->id];
});
$factory->define(App\Industry::class, function (Faker\Generator $faker) {
    $name = ucwords(join(' ', $faker->words(rand(1, 4))));
    return ['name' => $name, 'slug' => str_slug($name)];
});
Example #3
0
 /**
  * Show the specified file in the browser.
  *
  * @author Jonas Schwartz <*****@*****.**>
  * @param string $path
  * @return mixed
  */
 public function showFile($path)
 {
     // We need to clean the output buffer before showing the file
     ob_end_clean();
     ob_start();
     $type = \File::mimeType($path);
     return response()->file($path, ['Content-Type' => $type]);
 }
Example #4
0
 /**
  * @param $path
  * @param $filename
  * @return static
  */
 public static function createFromFile($path, $filename)
 {
     $model = new static();
     return $model->create(['filename' => $filename, 'temp_filename' => \File::basename($path), 'file_type' => \File::mimeType($path)]);
 }
Example #5
0
 private function setTmpImage($upload_file)
 {
     $image_types = array('image/png', 'image/gif', 'image/jpeg', 'image/jpg');
     if (in_array(\File::mimeType($upload_file), $image_types)) {
         switch (\File::mimeType($upload_file)) {
             case 'image/png':
                 $img = imagecreatefrompng($upload_file->getRealPath());
                 break;
             case 'image/gif':
                 $img = imagecreatefromgif($upload_file->getRealPath());
                 break;
             case 'image/jpeg':
             case 'image/jpg':
             default:
                 $img = imagecreatefromjpeg($upload_file->getRealPath());
                 $exif = read_exif_data($upload_file->getRealPath());
                 if (isset($exif['Orientation'])) {
                     switch ($exif['Orientation']) {
                         case 8:
                             $img = imagerotate($img, 90, 0);
                             break;
                         case 3:
                             $img = imagerotate($img, 180, 0);
                             break;
                         case 6:
                             $img = imagerotate($img, -90, 0);
                             break;
                     }
                 }
         }
         imagepng($img, $upload_file->getRealPath());
         return $img;
     } else {
         return null;
     }
 }
Example #6
0
 private function setTmpImage($upload_file)
 {
     $image_types = array('image/png', 'image/gif', 'image/jpeg', 'image/jpg');
     $image_path = $upload_file instanceof UploadedFile ? $upload_file->getRealPath() : $upload_file;
     $img = null;
     if (in_array(\File::mimeType($upload_file), $image_types)) {
         switch (\File::mimeType($upload_file)) {
             case 'image/png':
                 $img = imagecreatefrompng($image_path);
                 break;
             case 'image/gif':
                 break;
             case 'image/jpeg':
             case 'image/jpg':
             default:
                 $img = imagecreatefromjpeg($image_path);
                 try {
                     $exif = exif_read_data($image_path);
                     if (isset($exif['Orientation'])) {
                         switch ($exif['Orientation']) {
                             case 8:
                                 $img = imagerotate($img, 90, 0);
                                 break;
                             case 3:
                                 $img = imagerotate($img, 180, 0);
                                 break;
                             case 6:
                                 $img = imagerotate($img, -90, 0);
                                 break;
                         }
                     }
                     imagejpeg($img, $image_path);
                 } catch (\Exception $e) {
                     //ignore cannot read exif
                 }
         }
         return $img;
     } else {
         return null;
     }
 }
Example #7
0
        Route::post('people', 'PeopleController@sort');
    });
    // DELETE ACTIONS
    Route::delete('accountancy/file_delete/{path}', 'AccountancyController@FileDelete')->where('path', '.+');
    Route::delete('links/delete_pdf/{id}', 'LinksController@DeletePdf');
    // RESOURCES
    Route::resource('menu', 'MenuController');
    Route::resource('contents', 'ContentController');
    Route::resource('banners', 'ContentController');
    Route::resource('galleries', 'ContentController');
    Route::resource('links', 'ContentController');
    Route::resource('people', 'ContentController');
    Route::resource('link', 'LinksController');
    Route::resource('photos', 'PhotosController');
    Route::resource('person', 'PeopleController');
    Route::resource('company', 'CompanyController');
    Route::resource('accountancy', 'AccountancyController');
    Route::resource('user', 'UserController');
    // SUBSCRIBE PACKAGE
    Route::get('subscribes', 'AdminController@subscribes');
    /**
     * @ ACCOUNTANCY FILE
     */
    Route::get('accountancy/file/{path}', function ($path) {
        $path = storage_path('app/accountancy/' . $path);
        $mime = \File::mimeType($path);
        return \Response::download($path, null, ['Content-type', $mime]);
    })->where('path', '.+');
});
// CUSTOM ROUTES
\File::exists(base_path('custom/routes.php')) ? require_once base_path('/custom/routes.php') : null;
Example #8
0
 protected function getTestFile($file)
 {
     $copyFileName = __DIR__ . '/studs/tmp_file.' . pathinfo($file)['extension'];
     file_put_contents($copyFileName, file_get_contents($file));
     $fileUpload = new \Symfony\Component\HttpFoundation\File\UploadedFile($copyFileName, pathinfo($file)['basename'], \File::mimeType($file), \File::size($file), 0, 1);
     return $fileUpload;
 }
Example #9
0
<?php

/**
 * Load tenant assets outside the public folder with this route.
 */
Route::get('asset/{path}', ['as' => 'asset', function ($path) {
    $asset = tenant_path(tenant(), '/assets/' . $path);
    if (!file_exists($asset)) {
        abort(404);
    }
    $mime = File::mimeType($asset);
    if ($mime == 'text/plain' && File::extension($asset) == 'css') {
        $mime = 'text/css';
    }
    return response(file_get_contents($asset), 200, ['Content-Type' => $mime]);
}])->where('path', '(.*)');
 /**
  * Transform the source file.
  *
  * @param \CipeMotion\Medialibrary\Entities\File $file
  *
  * @return \CipeMotion\Medialibrary\Entities\Transformation
  */
 public function transform(File $file)
 {
     // Extract config options
     $extension = array_get($this->config, 'extension', 'mp4');
     $videoCodec = strtolower(array_get($this->config, 'video.codec', 'h264'));
     $videoResolution = array_get($this->config, 'video.resolution', '1280x720');
     $audioCodec = strtolower(array_get($this->config, 'audio.codec', 'aac'));
     // Retrieve the file info and generate a thumb
     list($preview, $thumb, $fileInfo) = $this->generateThumbAndRetrieveFileInfo($file);
     // Build up the base settings
     $cloudconvertSettings = ['inputformat' => $file->extension, 'outputformat' => $extension, 'wait' => true, 'input' => 'download', 'file' => $file->downloadUrl, 'converteroptions' => ['video_codec' => 'copy', 'audio_codec' => 'copy', 'faststart' => true]];
     // Collect the streams from the video info
     $streams = collect($fileInfo->info->streams);
     // Find the video stream with the correct codec if any
     $videoStream = $streams->first(function ($stream) use($videoCodec, $videoResolution) {
         return $stream->codec_type === 'video' && strtolower($stream->codec_name) === $videoCodec && "{$stream->width}x{$stream->height}" === $videoResolution;
     });
     // If there is no compataible video stream, reencode it
     if (empty($videoStream)) {
         $cloudconvertSettings['converteroptions']['video_codec'] = $videoCodec;
         $cloudconvertSettings['converteroptions']['video_resolution'] = $videoResolution;
     }
     // Find the audio stream with the correct codec if any
     $audioStream = $streams->first(function ($stream) use($audioCodec) {
         return $stream->codec_type === 'audio' && strtolower($stream->codec_name) === $audioCodec;
     });
     // If there is no compataible audio stream, reencode it
     if (empty($audioStream)) {
         $cloudconvertSettings['converteroptions']['audio_codec'] = $audioCodec;
     }
     // Respect the cloudconvert timeout
     if (!is_null(config('services.cloudconvert.timeout'))) {
         $cloudconvertSettings['timeout'] = config('services.cloudconvert.timeout');
     }
     // Run the conversion
     $convert = $this->api->convert($cloudconvertSettings)->wait();
     // Get a temp path
     $destination = get_temp_path();
     // Download the converted video file
     copy('https:' . $convert->output->url, $destination);
     // We got it all, cleanup!
     $fileInfo->delete();
     $convert->delete();
     // Setup the transformation properties
     $transformation = new Transformation();
     $transformation->name = $this->name;
     $transformation->type = $file->type;
     $transformation->size = Filesystem::size($destination);
     $transformation->width = explode('x', $videoResolution)[0];
     $transformation->height = explode('x', $videoResolution)[1];
     $transformation->mime_type = Filesystem::mimeType($destination);
     $transformation->extension = $extension;
     $transformation->completed = true;
     // Get the disk and a stream from the cropped image location
     $disk = Storage::disk($file->disk);
     $stream = fopen($destination, 'r+');
     // Either overwrite the original uploaded file or write to the transformation path
     if (array_get($this->config, 'default', false)) {
         $disk->put("{$file->id}/upload.{$transformation->extension}", $stream);
         if ($transformation->extension !== $file->extension) {
             $disk->delete("{$file->id}/upload.{$file->extension}");
         }
     } else {
         $disk->put("{$file->id}/{$transformation->name}.{$transformation->extension}", $stream);
     }
     // Save the preview and thumb transformations
     $file->transformations()->save($thumb);
     $file->transformations()->save($preview);
     // Close the stream again
     if (is_resource($stream)) {
         fclose($stream);
     }
     return $transformation;
 }
Example #11
0
 function prepareFileUpload($path)
 {
     return new \Symfony\Component\HttpFoundation\File\UploadedFile($path, null, \File::mimeType($path), null, null, true);
 }
Example #12
0
 public static function uploadImage($file, $extension, $uploadDir = '')
 {
     if ($file && \File::exists($file) && \File::size($file) && !is_dir($file) && preg_match('/image/', \File::mimeType($file)) && $extension) {
         $img = Image::make($file);
         $fileName = uniqid() . '.' . $extension;
         $uploadDirectory = self::getUploadDirectory($uploadDir);
         if ($img->save(public_path() . "/" . $uploadDirectory . $fileName)) {
             return $uploadDirectory . $fileName;
         } else {
             return null;
         }
     } else {
         return null;
     }
 }
Example #13
0
 public function prepareAssetSourceData($asset, $frontmatter)
 {
     $filename = basename($asset);
     $sequence = array_search($filename, array_keys($frontmatter));
     if (isset($frontmatter[$filename])) {
         $data = $frontmatter[$filename];
     }
     $data['uri'] = $asset;
     $data['sequence'] = isset($sequence) ? $sequence + 1 : 1;
     $data['mimetype'] = \File::mimeType($asset);
     return $data;
 }
Example #14
0
 function fileInfo(FileModel $file, $suffix = false)
 {
     if ($suffix) {
         $_filename = explode('.', $file->filename);
         $file->filename = implode('.', [$_filename[0], $suffix, $_filename[1]]);
     }
     $path = storage_path('app/' . $file->filename);
     $_file = File::get($path);
     $type = File::mimeType($path);
     $getId3 = new GetId3();
     $mimeType = $getId3->analyze($path)['mime_type'];
     return ['file' => $_file, 'type' => $mimeType, 'path' => $path];
 }