Exemplo n.º 1
0
 public function upload($path, $filename, $file)
 {
     // Verifica se o diretório permite escrita
     if (!File::isWritable(storage_path('app/' . $path))) {
         return ['cod' => '0', 'msg' => '[ERRO] Diretorio sem permissão de escrita.'];
     }
     if (Storage::exists('app/' . $path . '/' . $filename)) {
         return ['cod' => '0', 'msg' => '[ERRO] Já existe um arquivo com este nome.'];
     }
     return Storage::disk('local')->put($path . $filename, file_get_contents($file->getRealPath()));
 }
Exemplo n.º 2
0
 private function checkPathIsOk($path, $dir = null)
 {
     $path = rtrim($path, '/') . ($dir ? '/' . trim($dir, '/') : '');
     if (File::isDirectory($path) && File::isWritable($path)) {
         return true;
     } else {
         try {
             @File::makeDirectory($path, 0777, true);
             return true;
         } catch (\Exception $e) {
             Log::error('Uploader: ' . $e->getMessage());
             $this->results['error'] = $e->getMessage();
             return false;
         }
     }
 }
 protected function generateFile($code)
 {
     if (!File::isDirectory($this->path)) {
         File::makeDirectory($this->path);
     }
     if (File::isWritable($this->path)) {
         if (!File::isDirectory($this->path . $this->pathfile)) {
             File::makeDirectory($this->path . $this->pathfile);
         }
         if (File::isWritable($this->path . $this->pathfile)) {
             File::put($this->filename, $code);
             if (File::exists($this->filename)) {
                 return "File " . $this->filename . " created successfully";
             } else {
                 return "no se pudo crear " . $this->filename;
             }
         }
         return "No se puede escribir o no existe " . $this->path . $this->pathfile;
     }
     return "No se puede escribir o no existe " . $this->path;
 }
Exemplo n.º 4
0
 /**
  * Perform necessary checks
  * @return boolean
  * @throws \RuntimeException
  */
 public function setup()
 {
     // Check if files directory has been created
     if (!File::isDirectory($this->config['filePath'])) {
         throw new \RuntimeException('It looks like config file has not been published. Use php artisan config:publish command.');
     }
     // Check if files directory has been created
     if (!File::isWritable($this->config['filePath'])) {
         throw new \RuntimeException('Please make sure that files directory is writable.');
     }
     // initialized fileNumber with database on first run
     if (!Schema::hasTable($this->config['filenum_table']['tableName'])) {
         $this->createTable($this->config['filenum_table']);
         FileNumber::create(array($this->config['filenum_table']['fieldName'] => $this->config['fileNumber']));
         $this->config['header_record']['header_bath_number'] = $this->padWithZero();
         $this->config['fileName'] .= $this->padWithZero() . '.tmp';
         $this->setFileNumber();
     } else {
         $this->setFileName();
     }
     // initialized dr_consignment_number with database on first run
     if (!Schema::hasTable($this->config['consnum_table']['tableName'])) {
         $this->createTable($this->config['consnum_table']);
         ConsNumber::create(array($this->config['consnum_table']['fieldName'] => $this->config['dr_consignment_number']['number']));
     } else {
         $this->getConsignmentNumber();
     }
     /**
      * Set header type to SKEL
      * Allowing UK Domestic services despatches only
      * 
      * config default: DSCC - UK Domestic collection request
      */
     if ($this->config['header_record']['header_file_type'] === 'SKEL') {
         $this->config['deliveryDetails']['dr_location_id'] = 1;
     }
     return true;
 }
Exemplo n.º 5
0
 /**
  * Get upload path with date folders
  * @param $date
  * @throws \Symfony\Component\HttpFoundation\File\Exception\FileException
  * @throws \Doctrine\Common\Proxy\Exception\InvalidArgumentException
  * @return string
  */
 public function getUploadFolder($date = null)
 {
     // Check that a date was given
     if (is_null($date)) {
         $date = Carbon::now();
     } elseif (!is_a($date, 'Carbon')) {
         throw new InvalidArgumentException('Must me a Carbon object');
     }
     // Get the configuration value for the upload path
     $path = static::$app['config']->get('cabinet::upload_folder');
     $path = $this->cleanPath($path);
     // Add the project base to the path
     $path = static::$app['path.base'] . $path;
     $this->dateFolderPath = str_replace('-', '/', $date->toDateString()) . '/';
     // Parse in to a folder format. 2013:03:30 -> 2013/03/30/{filename}.jpg
     $folder = $path . $this->dateFolderPath;
     // Check to see if the upload folder exists
     if (!File::exists($folder)) {
         // Try and create it
         if (!File::makeDirectory($folder, static::$app['config']->get('cabinet::upload_folder_permission_value'), true)) {
             throw new FileException('Directory is not writable. Please make upload folder writable.');
         }
     }
     // Check that the folder is writable
     if (!File::isWritable($folder)) {
         throw new FileException('Folder is not writable.');
     }
     return $folder;
 }