/**
  * 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);
 }
Ejemplo n.º 2
1
 function delete_image_cdn($img)
 {
     if (strpos($img, "cloudinary")) {
         $x = explode("/", $img);
         $y = explode(".", $x[count($x) - 1]);
         if ($y[0] != "default") {
             \Cloudinary\Uploader::destroy($y[0], array("invalidate" => true));
         }
     }
 }
Ejemplo n.º 3
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);
 }
Ejemplo n.º 4
0
function wppa_delete_from_cloudinary($id)
{
    $prefix = is_multisite() && !WPPA_MULTISITE_GLOBAL ? $blog_id . '-' : '';
    $pub_id = $prefix . $id;
    $args = array("invalidate" => true);
    \Cloudinary\Uploader::destroy($pub_id, $args);
}
Ejemplo n.º 5
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');
 }
 /**
  * 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]);
 }
 public function uploadAsset(AssetFileModel $savedAsset)
 {
     try {
         \Cloudinary\Uploader::upload($savedAsset->url, ['public_id' => $this->getAssetHandle($savedAsset)]);
     } catch (\Cloudinary\Error $e) {
         $this->handleError($e->getMessage());
     }
 }
Ejemplo n.º 8
0
 public function test_allow_missing()
 {
     Curl::mockUpload($this);
     Uploader::create_zip(array("tags" => $this->tag, "allow_missing" => TRUE));
     assertUrl($this, '/image/generate_archive');
     assertParam($this, "tags[0]", $this->tag);
     assertParam($this, "allow_missing", 1, "should support the 'allow_missing' parameter");
 }
Ejemplo n.º 9
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;
}
 /**
  * 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();
         }
     }
 }
Ejemplo n.º 11
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;
 }
Ejemplo 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');
 }
 /**
  * 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;
 }
 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);
 }
Ejemplo n.º 15
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 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")));
}
Ejemplo n.º 17
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')));
}
Ejemplo n.º 18
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;
 }
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);
    }
}
Ejemplo n.º 20
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']));*/
 }
Ejemplo n.º 21
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();
     }
 }
Ejemplo n.º 22
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;
 }
Ejemplo n.º 23
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();
     }
 }
Ejemplo n.º 24
0
 public function rename($path, $newpath)
 {
     return Uploader::rename($path, $newpath);
 }
Ejemplo n.º 25
0
 function create_upload_preset($options = array())
 {
     $params = \Cloudinary\Uploader::build_upload_params($options);
     return $this->call_api("post", array("upload_presets"), array_merge($params, $this->only($options, array("name", "unsigned", "disallow_public_id"))), $options);
 }
 public function deleteImage(Image $image)
 {
     Uploader::destroy($image->getId());
 }
 /**
  * Delete file using public ID
  * 
  * @param string $publicId
  * @param array $options
  * @throws CakeException
  */
 public function delete($publicId = null, $options = array())
 {
     if (!empty($publicId)) {
         $status = \Cloudinary\Uploader::destroy($publicId, $options);
         if ($status['result'] == 'ok') {
             return true;
         } else {
             throw new CakeException(__d('cake_dev', $publicId . ' is not found or already deleted.'));
         }
     } else {
         throw new CakeException(__d('cake_dev', 'Public ID is missing'));
     }
 }
Ejemplo 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'];
Ejemplo 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");
Ejemplo n.º 30
0
 /**
  * Delete media
  */
 public function delete()
 {
     /*  	if (isset($this->id)) {
       		if (file_exists($this->get_path(self::STYLE_ROOT)))
     		  	unlink($this->get_path(self::STYLE_ROOT));
     	}*/
     if ($this->public_id) {
         \Cloudinary\Uploader::destroy($this->public_id);
     }
     return parent::delete();
 }