示例#1
0
 /**
  * Saves a new image
  * @param string $imageName
  * @param string $imageData
  * @param string $type
  * @return Image
  */
 private function saveNew($imageName, $imageData, $type)
 {
     $storage = $this->getStorage();
     $secureUploads = Setting::get('app-secure-images');
     $imageName = str_replace(' ', '-', $imageName);
     if ($secureUploads) {
         $imageName = str_random(16) . '-' . $imageName;
     }
     $imagePath = '/uploads/images/' . $type . '/' . Date('Y-m-M') . '/';
     while ($storage->exists($imagePath . $imageName)) {
         $imageName = str_random(3) . $imageName;
     }
     $fullPath = $imagePath . $imageName;
     $storage->put($fullPath, $imageData);
     $userId = auth()->user()->id;
     $image = Image::forceCreate(['name' => $imageName, 'path' => $fullPath, 'url' => $this->getPublicUrl($fullPath), 'type' => $type, 'created_by' => $userId, 'updated_by' => $userId]);
     return $image;
 }
示例#2
0
 /**
  * Saves a new image
  * @param string $imageName
  * @param string $imageData
  * @param string $type
  * @param int $uploadedTo
  * @return Image
  * @throws ImageUploadException
  */
 private function saveNew($imageName, $imageData, $type, $uploadedTo = 0)
 {
     $storage = $this->getStorage();
     $secureUploads = setting('app-secure-images');
     $imageName = str_replace(' ', '-', $imageName);
     if ($secureUploads) {
         $imageName = str_random(16) . '-' . $imageName;
     }
     $imagePath = '/uploads/images/' . $type . '/' . Date('Y-m-M') . '/';
     if ($this->isLocal()) {
         $imagePath = '/public' . $imagePath;
     }
     while ($storage->exists($imagePath . $imageName)) {
         $imageName = str_random(3) . $imageName;
     }
     $fullPath = $imagePath . $imageName;
     try {
         $storage->put($fullPath, $imageData);
         $storage->setVisibility($fullPath, 'public');
     } catch (Exception $e) {
         throw new ImageUploadException('Image Path ' . $fullPath . ' is not writable by the server.');
     }
     if ($this->isLocal()) {
         $fullPath = str_replace_first('/public', '', $fullPath);
     }
     $imageDetails = ['name' => $imageName, 'path' => $fullPath, 'url' => $this->getPublicUrl($fullPath), 'type' => $type, 'uploaded_to' => $uploadedTo];
     if (user()->id !== 0) {
         $userId = user()->id;
         $imageDetails['created_by'] = $userId;
         $imageDetails['updated_by'] = $userId;
     }
     $image = Image::forceCreate($imageDetails);
     return $image;
 }
示例#3
0
 /**
  * Saves a new image
  * @param string $imageName
  * @param string $imageData
  * @param string $type
  * @return Image
  * @throws ImageUploadException
  */
 private function saveNew($imageName, $imageData, $type)
 {
     $storage = $this->getStorage();
     $secureUploads = Setting::get('app-secure-images');
     $imageName = str_replace(' ', '-', $imageName);
     if ($secureUploads) {
         $imageName = str_random(16) . '-' . $imageName;
     }
     $imagePath = '/uploads/images/' . $type . '/' . Date('Y-m-M') . '/';
     while ($storage->exists($imagePath . $imageName)) {
         $imageName = str_random(3) . $imageName;
     }
     $fullPath = $imagePath . $imageName;
     if (!is_writable(dirname(public_path($fullPath)))) {
         throw new ImageUploadException('Image Directory ' . public_path($fullPath) . ' is not writable by the server.');
     }
     $storage->put($fullPath, $imageData);
     $imageDetails = ['name' => $imageName, 'path' => $fullPath, 'url' => $this->getPublicUrl($fullPath), 'type' => $type];
     if (auth()->user() && auth()->user()->id !== 0) {
         $userId = auth()->user()->id;
         $imageDetails['created_by'] = $userId;
         $imageDetails['updated_by'] = $userId;
     }
     $image = Image::forceCreate($imageDetails);
     return $image;
 }