upload() public static method

public static upload ( $file, $options = [] )
 /**
  * Upload files to cloudinary
  *
  */
 public function upload(UploadRequest $request)
 {
     $judul_file = $request->get('judul');
     $gambar = $request->file('gambar');
     $nama_file = Str::slug($judul_file);
     $upload = \Cloudinary\Uploader::upload($gambar, array("public_id" => $nama_file));
     return redirect()->to($nama_file);
 }
Exemplo n.º 2
0
 /**
  * Upload a file to cloudinary.
  *
  * @param \Symfony\Component\HttpFoundation\File\UploadedFile
  * @param array
  * @return array
  */
 public function uploadFile($file, $options = [])
 {
     if (empty($options)) {
         $options = ['crop' => 'fill', 'width' => '240', 'height' => '240'];
     }
     return Uploader::upload($file, $options);
 }
 /**
  * Creates a new Tweet model.
  * If creation is successful, the browser will be redirected to the 'view' page.
  * @return mixed
  */
 public function actionCreate()
 {
     $model = new Tweet();
     if ($model->load(Yii::$app->request->post())) {
         $model->owner = Yii::$app->user->identity->username;
         $date = new \DateTime();
         $model->timestamp = $date->getTimestamp();
         if ($model->save()) {
             //Upload images if need be.
             $image = UploadedFile::getInstances($model, 'image');
             \Cloudinary::config(array("cloud_name" => "dxqmggd5a", "api_key" => "314154111631994", "api_secret" => "KE-AgYwX8ecm8N2omI22RDVmFv4"));
             foreach ($image as $file) {
                 $uploadResult = \Cloudinary\Uploader::upload($file->tempName);
                 $myConnection = new MediaConnections();
                 $myConnection->tweet = $model->id;
                 $myConnection->url = $uploadResult['url'];
                 $myConnection->timestamp = $model->timestamp;
                 $myConnection->save();
             }
             User::findByUsername($model->owner)->createTweet();
             return $this->redirect(Yii::$app->request->referrer);
         }
     }
     return $this->render('create', ['model' => $model]);
 }
Exemplo n.º 4
0
 public function add()
 {
     if (!$_FILES['image']['name']) {
         return call('pages', 'error');
     }
     $uploadOk = 1;
     // check if image file is a actual image or fake image
     if (isset($_POST['submit'])) {
         $check = getimagesize($_FILES['image']['tmp_name']);
         if ($check !== false) {
             $uploadOk = 1;
         } else {
             $_SESSION['alert'] = "File is not an image.";
             $uploadOk = 0;
         }
     }
     if ($uploadOk == 0) {
         $_SESSION['alert'] = $_SESSION['alert'] . " Sorry, your file was not uploaded.";
     } else {
         $image = \Cloudinary\Uploader::upload($_FILES["image"]["tmp_name"]);
         if (!empty($image)) {
             Image::create($image['public_id'], $image['url'], basename($image['url']));
             $_SESSION['notice'] = "The image " . basename($_FILES['image']['name']) . " has been uploaded.";
         } else {
             $_SESSION['alert'] = "Sorry, there was an error uploading your file. ";
         }
     }
     redirect_to('images', 'index');
 }
 public function uploadAsset(AssetFileModel $savedAsset)
 {
     try {
         \Cloudinary\Uploader::upload($savedAsset->url, ['public_id' => $this->getAssetHandle($savedAsset)]);
     } catch (\Cloudinary\Error $e) {
         $this->handleError($e->getMessage());
     }
 }
Exemplo n.º 6
0
function create_photo($file_path, $orig_name)
{
    # Upload the received image file to Cloudinary
    $result = \Cloudinary\Uploader::upload($file_path, array("tags" => "backend_photo_album", "public_id" => $orig_name));
    unlink($file_path);
    error_log("Upload result: " . \PhotoAlbum\ret_var_dump($result));
    $photo = \PhotoAlbum\create_photo_model($result);
    return $result;
}
Exemplo n.º 7
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     Cloudinary::config(array("cloud_name" => "seniva", "api_key" => "572854663344648", "api_secret" => "8YqjessAxqDJeOtU4SUYUPedRV8"));
     $file = $request->file('image_file')->getRealPath();
     $image = Uploader::upload($file);
     $project = Project::create($request->only('title', 'description'));
     $project->images()->create(['public_id' => $image['public_id']]);
     return redirect()->route('admin_projects_path');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     if (rand(0, 1) == 1) {
         $url = "https://pixabay.com/api/?key=" . env('PIXABAY_API_KEY') . "&image_type=photo&category=buildings&safesearch=true&min_width=500";
         $json = file_get_contents($url);
         $json_data = json_decode($json, true);
         $pixa_json = $json_data['hits'];
         foreach ($pixa_json as $image) {
             $pictureUploadResult = \Cloudinary\Uploader::upload($image['webformatURL']);
             if ($pictureUploadResult == null) {
                 echo "Error uploading picture";
                 continue;
             }
             $picture = new Picture();
             $picture->description = "";
             $picture->url = $pictureUploadResult['secure_url'];
             $picture->cloudinary_public_id = $pictureUploadResult['public_id'];
             $picture->save();
             $junction = new PropertyPictureBridge();
             $all_properties = Property::all();
             $one_property = $all_properties[rand(0, count($all_properties) - 1)];
             $junction->property_id = $one_property->id;
             $junction->picture_id = $picture->id;
             $junction->save();
         }
     } else {
         $api_key = env('FLICKR_API_KEY');
         $query = 'new york city apartment';
         $url = "https://api.flickr.com/services/rest/?method=flickr.photos.search&api_key=" . $api_key . "&tags=" . urlencode($query) . "&safe_search=1&per_page=20&format=json";
         $json_data = file_get_contents($url);
         $json_data = substr($json_data, 14);
         $json_data = substr($json_data, 0, strlen($json_data) - 1);
         $json_data = json_decode($json_data, true);
         foreach ($json_data['photos']['photo'] as $photo) {
             $farm = $photo['farm'];
             $server = $photo['server'];
             $src = 'http://farm' . $farm . '.static.flickr.com/' . $server . '/' . $photo['id'] . '_' . $photo['secret'] . '_z.jpg';
             $pictureUploadResult = \Cloudinary\Uploader::upload($src);
             if ($pictureUploadResult == null) {
                 echo "Error uploading picture";
                 continue;
             }
             $picture = new Picture();
             $picture->description = "";
             $picture->url = $pictureUploadResult['secure_url'];
             $picture->cloudinary_public_id = $pictureUploadResult['public_id'];
             $picture->save();
             $junction = new PropertyPictureBridge();
             $all_properties = Property::all();
             $one_property = $all_properties[rand(0, count($all_properties) - 1)];
             $junction->property_id = $one_property->id;
             $junction->picture_id = $picture->id;
             $junction->save();
         }
     }
 }
 /**
  * Uploads raw contents to the service.
  *
  * @param string $contents
  * @return array    The meta of the file.
  */
 public function uploadContents($name, $contents)
 {
     // raw contents not allowed
     $tmpFilesystem = new Filesystem(new Local(storage_path('tmp/')));
     $tmpFilesystem->write($name, $contents);
     $meta = Uploader::upload(storage_path('tmp/' . $name));
     // force secure url
     $meta['url'] = $meta['secure_url'];
     return $meta;
 }
Exemplo n.º 10
0
 /**
  * Builds user data for saving in the database.
  *
  * @param Koya\User $user
  * @param $provider
  *
  * @return array
  */
 private function prepareUserData($user, $provider)
 {
     //Github uses avatar while facebook and twitter uses avatar_original for storing user image
     $avatar_url = $provider == 'github' ? $user->avatar : $user->avatar_original;
     //Upload user image to cloudinary
     $cloudinary_data = Uploader::upload($avatar_url);
     //Build data
     $data = ['name' => $user->name, 'username' => str_replace(' ', '.', strtolower($user->name)) . '.' . time(), 'email' => $user->email, 'password' => null, 'provider' => $provider, 'provider_id' => $user->id, 'provider_token' => $user->token, 'avatar' => $cloudinary_data['url'], 'cloudinary_id' => $cloudinary_data['public_id']];
     return $data;
 }
Exemplo n.º 11
0
 public function setUp()
 {
     \Cloudinary::reset_config();
     if (!\Cloudinary::config_get("api_secret")) {
         $this->markTestSkipped('Please setup environment for Upload test to run');
     }
     $this->tag = "php_test_" . rand(11111, 99999);
     Uploader::upload("tests/logo.png", array("tags" => array($this->tag)));
     Uploader::upload("tests/logo.png", array("tags" => array($this->tag), "width" => 10, "crop" => "scale"));
 }
Exemplo n.º 12
0
 /**
  * Upload avatar to Cloudinary and save the returned url to database
  *
  * @param Request $request
  * @return \Illuminate\Http\RedirectResponse|\Illuminate\Routing\Redirector
  */
 public function updateAvatar(Request $request)
 {
     if ($request['file']) {
         $result = Uploader::upload($request['file'], ["public_id" => Auth::user()->username . rand(1, 100)]);
         $profile = Profile::where('user_id', Auth::user()->id)->first();
         $profile->avatar = $result['url'];
         $profile->save();
     }
     return redirect('dashboard');
 }
Exemplo n.º 13
0
function wppa_upload_to_cloudinary($id)
{
    $prefix = is_multisite() && !WPPA_MULTISITE_GLOBAL ? $blog_id . '-' : '';
    $pub_id = $prefix . $id;
    $file = wppa_get_photo_path($id);
    $args = array("public_id" => $pub_id, "version" => get_option('wppa_photo_version', '1'), "invalidate" => true);
    if (file_exists($file)) {
        \Cloudinary\Uploader::upload($file, $args);
    }
}
Exemplo n.º 14
0
 public function upload($file, $options = array())
 {
     $options['return_error'] = false;
     $ret = \Cloudinary\Uploader::upload($file, $options);
     $preloaded = new \Cloudinary\PreloadedFile(\Cloudinary::signed_preloaded_image($ret));
     if ($this->verifyUpload && !$preloaded . is_valid()) {
         throw new \Exception("Error! Couldn't verify cloudinary response!");
     }
     $this->_identifier = $preloaded->extended_identifier();
 }
 public function run()
 {
     // Uncomment the below to wipe the table clean before populating
     DB::table('medias')->delete();
     $medias = array();
     foreach (range(1, 20) as $id) {
         $image = \Cloudinary\Uploader::upload("http://lorempixel.com/1024/720/?82533");
         $medias[] = ['public_id' => $image['public_id'], 'created_at' => new DateTime(), 'updated_at' => new DateTime()];
     }
     //// Uncomment the below to run the seeder
     DB::table('medias')->insert($medias);
 }
Exemplo n.º 16
0
 public function sendScreenshot($cloudName, $apiKey, $apiSecret, $authToken)
 {
     $this->say('Sending image');
     // Upload image
     Cloudinary::config(array('cloud_name' => $cloudName, 'api_key' => $apiKey, 'api_secret' => $apiSecret));
     $result = \Cloudinary\Uploader::upload(realpath(dirname(__FILE__) . '/tests/_output/InstallNenoCest.installNeno.fail.png'));
     $this->say('Image sent');
     $this->say('Creating Github issue');
     $client = new \Github\Client();
     $client->authenticate($authToken, \Github\Client::AUTH_HTTP_TOKEN);
     $client->api('issue')->create('Jensen-Technologies', 'neno', array('title' => 'Test error', 'body' => '![Screenshot](' . $result['secure_url'] . ')'));
 }
function wppa_upload_to_cloudinary($id)
{
    $prefix = is_multisite() && !WPPA_MULTISITE_GLOBAL ? $blog_id . '-' : '';
    $args = array("public_id" => $prefix . $id, "version" => get_option('wppa_photo_version', '1'), "invalidate" => true);
    // Try source first
    $file = wppa_get_source_path($id);
    // No source, use photofile
    if (!is_file($file)) {
        $file = wppa_get_photo_path($id);
    }
    // Doit
    if (is_file($file)) {
        \Cloudinary\Uploader::upload($file, $args);
    }
}
function do_uploads()
{
    global $files, $sample_paths, $default_upload_options, $eager_params;
    # public_id will be generated on Cloudinary's backend.
    $files["unnamed_local"] = \Cloudinary\Uploader::upload($sample_paths["pizza"], $default_upload_options);
    # Same image, uploaded with a public_id
    $files["named_local"] = \Cloudinary\Uploader::upload($sample_paths["pizza"], array_merge($default_upload_options, array("public_id" => "custom_name")));
    # Eager transformations are applied as soon as the file is uploaded, instead of waiting
    # for a user to request them.
    $files["eager"] = \Cloudinary\Uploader::upload($sample_paths["lake"], array_merge($default_upload_options, array("public_id" => "eager_custom_name", "eager" => $eager_params)));
    # In the two following examples, the file is fetched from a remote URL and stored in Cloudinary.
    # This allows you to apply the same transformations, and serve those using Cloudinary's CDN layer.
    $files["remote"] = \Cloudinary\Uploader::upload($sample_paths["couple"], $default_upload_options);
    $files["remote_trans"] = \Cloudinary\Uploader::upload($sample_paths["couple"], array_merge($default_upload_options, array("width" => 500, "height" => 500, "crop" => "fit", "effect" => "saturation:-70")));
}
Exemplo n.º 19
0
function do_uploads()
{
    global $files, $sample_paths, $default_upload_options, $eager_params;
    # public_id will be generated on Cloudinary's backend.
    $files['unnamed_local'] = \Cloudinary\Uploader::upload($sample_paths['pizza'], $default_upload_options);
    # Same image, uploaded with a public_id
    $files['named_local'] = \Cloudinary\Uploader::upload($sample_paths['pizza'], array_merge($default_upload_options, array('public_id' => 'custom_name')));
    # Eager transformations are applied as soon as the file is uploaded, instead of waiting
    # for a user to request them.
    $files['eager'] = \Cloudinary\Uploader::upload($sample_paths['lake'], array_merge($default_upload_options, array('public_id' => 'eager_custom_name', 'eager' => $eager_params)));
    # In the two following examples, the file is fetched from a remote URL and stored in Cloudinary.
    # This allows you to apply the same transformations, and serve those using Cloudinary's CDN layer.
    $files['remote'] = \Cloudinary\Uploader::upload($sample_paths['couple'], $default_upload_options);
    $files['remote_trans'] = \Cloudinary\Uploader::upload($sample_paths['couple'], array_merge($default_upload_options, array('width' => 500, 'height' => 500, 'crop' => 'fit', 'effect' => 'saturation:-70')));
}
Exemplo n.º 20
0
 protected function filter_project_input()
 {
     $input = Input::all();
     foreach (['profile', 'cover'] as $name) {
         if (Input::file($name) && Input::file($name)->isValid()) {
             $res = \Cloudinary\Uploader::upload(Input::file($name)->getRealPath());
             if ($res && isset($res['public_id'])) {
                 $media = Media::create(['public_id' => $res['public_id']]);
                 $input[$name . '_media_id'] = $media->id;
             }
             unset($input[$name]);
         }
     }
     return $input;
 }
Exemplo n.º 21
0
 public function testFailed(\Codeception\Event\FailEvent $e)
 {
     // Upload image
     Cloudinary::config(array('cloud_name' => $this->config['cloud_name'], 'api_key' => $this->config['api_key'], 'api_secret' => $this->config['api_secret']));
     $result = \Cloudinary\Uploader::upload(realpath(dirname(__FILE__) . '/../_output/InstallNenoCest.installNeno.fail.png'));
     /*
     		// Create Github issue
     		$client = new \Github\Client();
     		$token  = $this->config['token'];
     
     		$client->authenticate($token, \Github\Client::AUTH_URL_TOKEN);
     
     		$client
     			->api('issue')
     			->create('Jensen-Technologies', 'neno', array ('title' => 'Issue testing Neno', 'body' => $result['secure_url']));*/
 }
Exemplo n.º 22
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $url = "https://randomuser.me/api/?results=50&key=" . env('RANDOMUSER_API_KEY') . "&nat=us";
     $json = file_get_contents($url);
     $json_data = json_decode($json, true);
     file_put_contents('current_userset.txt', $json);
     foreach ($json_data['results'] as $result) {
         $user = new User();
         $user->email = $result['user']['email'];
         $user->password = bcrypt($result['user']['password']);
         $user->first_name = ucfirst($result['user']['name']['first']);
         $user->last_name = ucfirst($result['user']['name']['last']);
         $user->phone_number = $result['user']['phone'];
         $user->number_of_degrees = 1;
         $user->save();
         $degree = new Degree();
         $degree->year = rand(1923, 2010);
         $degree->user_id = $user->id;
         $faculties = array('arts_and_science', 'education', 'engineering_and_applied_science', 'health_science', 'law', 'business', 'graduate_studies', 'policy_studies');
         $types = array('ba', 'bcmp', 'bfa', 'bphe', 'bs', 'bsce', 'bcomm', 'msc', 'phd');
         $degree->faculty = $faculties[array_rand($faculties)];
         $degree->type = $types[array_rand($types)];
         $degree->primary_degree = true;
         $degree->save();
         $pictureUploadResult = \Cloudinary\Uploader::upload($result['user']['picture']['large']);
         if ($pictureUploadResult == null) {
             echo "Error uploading picture for " . $result['user']['name']['first'] . $result['user']['name']['last'];
             continue;
         }
         $picture = new Picture();
         $picture->description = "";
         $picture->url = $pictureUploadResult['secure_url'];
         $picture->cloudinary_public_id = $pictureUploadResult['public_id'];
         $picture->save();
         $junction = new UserPictureBridge();
         $junction->user_id = $user->id;
         $junction->picture_id = $picture->id;
         $junction->save();
     }
 }
Exemplo n.º 23
0
 public function getItem()
 {
     $state = $this->getState();
     if ($state->container) {
         $container = $this->getService('com://admin/cloudinary.model.accounts')->slug($state->container)->getItem();
     } else {
         // Select default account
         $container = $this->getService('com://admin/cloudinary.model.accounts')->default(1)->getItem();
     }
     Cloudinary::config(array('cloud_name' => $container->cloud_name, 'api_key' => $container->api_key, 'api_secret' => $container->api_secret));
     // Force the path to a string so object with __toString() function will work
     $this->set('path', (string) $state->path);
     if (parent::getItem()->isNew()) {
         if (!$state->type) {
             $image = \Cloudinary\Uploader::upload(JPATH_FILES . '/' . $state->path);
         }
         $this->_item = $this->getRow()->setData(array('public_id' => $state->type ? $state->path : $image['public_id'], 'path' => $state->path, 'url' => $state->type ? '' : $image['url'], 'format' => $state->type ? '' : $image['format'], 'cloudinary_account_id' => $container->id));
         $this->_item->save();
     }
     if ($state->flags) {
         if (is_array($state->flags)) {
             $state->flags = implode('.', $state->flags);
         }
     }
     $file = $state->type ? $this->_item->public_id : $this->_item->public_id . '.' . $this->_item->format;
     $this->_item->setData(array('url' => cloudinary_url($file, $state->toArray())));
     if ($state->cache) {
         $this->_item->setData(array('url' => $this->_item->getImage($this->_item->url, $state->toArray())));
     }
     if ($state->getsize) {
         $curl = curl_init($this->_item->url);
         curl_setopt_array($curl, array(CURLOPT_HTTPHEADER => array('Range: bytes=0-32768'), CURLOPT_RETURNTRANSFER => 1));
         $image = imagecreatefromstring(curl_exec($curl));
         $this->_item->setData(array('width' => imagesx($image), 'height' => imagesy($image)));
         curl_close($curl);
     }
     $this->_item->setData(array('attribs' => KHelperArray::toString($state->attribs)));
     return $this->_item;
 }
Exemplo n.º 24
0
 public function upload(SS_HTTPRequest $request)
 {
     $name = $this->getName();
     $postVars = $request->postVar($name);
     $tmpFileName = null;
     if (isset($postVars['tmp_name']) && isset($postVars['tmp_name']['file']) && !empty($postVars['tmp_name']['file'])) {
         $tmpFileName = $postVars['tmp_name']['file'];
     }
     if ($tmpFileName && is_uploaded_file($tmpFileName)) {
         CloudinaryFile::get_api();
         $arrRet = Uploader::upload($tmpFileName);
         Session::set('public_id', $arrRet['secure_url']);
         Session::save();
     }
 }
Exemplo n.º 25
0
 public function upload($path, $contents)
 {
     return Uploader::upload(new DataUri($contents), ['public_id' => $path]);
 }
 public function upload(Image $image)
 {
     Uploader::upload((string) $image, array("public_id" => $image->getId()));
 }
 /**
  * Upload file
  * 
  * @param string $file - file with absolute path. E.g., /your_path/your_image.png
  * @param array $options
  * @throws CakeException
  */
 public function upload($file = null, $options = array())
 {
     if (!empty($file)) {
         if (file_exists($this->path . DS . $file)) {
             $status = \Cloudinary\Uploader::upload($this->path . DS . $file, $options);
             return $this->_extractUploadStatus($status);
         } else {
             throw new CakeException(__d('cake_dev', $this->path . DS . $file . ' is missing'));
         }
     } else {
         throw new CakeException(__d('cake_dev', $file . ' is missing'));
     }
 }
Exemplo n.º 28
0
     $product_name = $_POST['product_name'];
     $brand = $_POST['brand'];
     $gender = $_POST['gender'];
     $mrp = $_POST['mrp'];
     $ship_charge = $_POST['ship_charge'];
     $sizes = $_POST['sizes'];
     $cod = $_POST['cod'];
     $color = $_POST['color'];
     $condition = $_POST['condition'];
     $type = $_POST['type'];
     $specs = $_POST['specs'];
     echo "got paarams waiting for imGE";
     //$product_image=($_POST['img']);
     //echo $_POST['img'];
     //die();
     \Cloudinary\Uploader::upload("https://pbs.twimg.com/profile_images/641377009281536000/p_IIHGDf.jpg");
     //Save the product details
     $user_data = array('product_name' => $product_name, 'brand' => $brand, 'gender' => $gender, 'mrp' => $mrp, 'ship_charge' => $ship_charge, 'sizes' => $sizes, 'cod' => $cod, 'color' => $color, 'condition' => $condition, 'specs' => $specs, 'seller' => $seller);
     $collection->save($user_data);
     $response["success"] = 1;
     $response["message"] = "Shoes' Entry Registered";
     header('location:categories.html');
     die(json_encode($response));
 } else {
     $response["success"] = 0;
     $response["message"] = "Error in registering Shoes";
     die(json_encode($response));
 }
 // Registering for Watches
 if ($category == 'watches') {
     $product_name = $_POST['product_name'];
Exemplo n.º 29
0
    // Check file size
    if ($_FILES["img"]["size"] > 1000000) {
        echo "Sorry, your file is too large.";
        $uploadOk = 0;
    }
    // Allow certain file formats
    if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
        echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
        $uploadOk = 0;
    }
    // Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {
        echo "Sorry, your file was not uploaded.";
        // if everything is ok, try to upload file
    } else {
        if ($d = \Cloudinary\Uploader::upload($_FILES["img"]["tmp_name"], array("crop" => "limit", "width" => "2000", "height" => "2000", "eager" => array(array("width" => 200, "height" => 200, "crop" => "thumb", "gravity" => "face"))))) {
            print_r($d);
            if ($insert_id = App::registerImage($d['public_id'], $d['url'], $d)) {
                $user->setProfilePicture($insert_id);
            }
            Tools::redirect("../../profile.php?status=1");
        } else {
            echo "Sorry, there was an error uploading your file.";
            Tools::redirect("../../profile.php?status=2");
        }
    }
    //redirect_to("../../add_teacher.php?status=1");
} elseif (Tools::valuePost("edit_profile")) {
    //redirect_to("../../add_teacher.php?status=2");
}
Tools::redirect("../../profile.php?status=6");
Exemplo n.º 30
0
 /**
  * Update media
  */
 public function update($path)
 {
     if (!file_exists($path)) {
         return false;
     }
     if ($this->public_id) {
         \Cloudinary\Uploader::destroy($this->public_id);
     }
     $res = \Cloudinary\Uploader::upload($path);
     $this->public_id = $res['public_id'];
     return parent::update();
 }