当前位置: 首页>>代码示例>>PHP>>正文


PHP S3::putObjectFile方法代码示例

本文整理汇总了PHP中S3::putObjectFile方法的典型用法代码示例。如果您正苦于以下问题:PHP S3::putObjectFile方法的具体用法?PHP S3::putObjectFile怎么用?PHP S3::putObjectFile使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在S3的用法示例。


在下文中一共展示了S3::putObjectFile方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: _upload_to_amazon

 protected function _upload_to_amazon($file_name, $path = '', $folder = false)
 {
     $this->load->library('S3');
     $bucket_name = $this->config->item('s3_bucket_name');
     if ($path == '') {
         $path = $this->config->item('csv_upload_path');
     }
     $folder_name = '';
     if ($folder) {
         $folder_name = $folder;
     }
     $s3 = new S3($this->config->item('s3_access_key'), $this->config->item('s3_secret_key'));
     echo "in _upload_to_amazon(): \n" . "  URL: http://{$bucket_name}/{$folder_name}{$file_name}\n";
     if (file_exists($path . $file_name)) {
         echo "final file size: " . filesize($path . $file_name) . "\n";
         try {
             $s3->putObjectFile($path . $file_name, $bucket_name, $folder_name . $file_name, S3::ACL_PUBLIC_READ);
             unset($s3);
         } catch (Exception $e) {
             echo '_upload_to_amazon exception: ', $e->getMessage(), "\n{$file_name}\n";
             log_message('error', '_upload_to_amazon exception: ', $e->getMessage(), "\n{$file_name}");
             unset($s3);
             return false;
         }
     }
     //exit;
     return true;
 }
开发者ID:kostya1017,项目名称:our,代码行数:28,代码来源:crowl.php

示例2: upload

 function upload()
 {
     $error = "test";
     if (isset($_POST['submitbtn'])) {
         if (array_key_exists('userFile', $_FILES)) {
             if ($_FILES['userFile']['error'] === UPLOAD_ERR_OK) {
                 $filename = $_FILES["userFile"]["name"];
                 $ext = pathinfo($filename, PATHINFO_EXTENSION);
                 $allowed = array("doc", "docx", "rtf", "pdf", "txt", "odf");
                 $fname = $_FILES["userFile"]["tmp_name"];
                 // Make sure extension matches
                 if (in_array($ext, $allowed)) {
                     if ($_FILES['userFile']['size'] < 2097152) {
                         $bucket = 'sublite-resumes';
                         //Can use existing configs when merging with sublite
                         $s3 = new S3("AKIAI7IVRJCSAWFTTS7Q", "B0qzRQJ1KlLy+STC2BspwT9oZONjt+U6sRNqaRr5");
                         $s3->putBucket($bucket, S3::ACL_PUBLIC_READ);
                         $actual_image_name = time() . '.' . $ext;
                         if ($s3->putObjectFile($fname, $bucket, $actual_image_name, S3::ACL_PUBLIC_READ)) {
                             $image = 'http://' . $bucket . '.s3.amazonaws.com/' . $actual_image_name;
                             return $image;
                         } else {
                             return "An unknown error occurred during upload!";
                         }
                         /*								// File validated; Upload the file! !!!Need to upload to S3!!!
                         								$uploaddir = 'resumes/';
                         								$uploadfile = basename($_FILES['userFile']['name']);
                         
                         								if (move_uploaded_file($_FILES['userFile']['tmp_name'], $uploaddir.$uploadfile)) {
                         								    return "File is valid, and was successfully uploaded.\n";
                         								} else {
                         								    return "An unknown error occurred during upload!";
                         								} */
                     } else {
                         $error = "Max file size exceeded!";
                     }
                 } else {
                     $error = "Bad file extension!";
                 }
             } else {
                 if ($_FILES['userFile']['error'] === UPLOAD_ERR_FORM_SIZE) {
                     $error = "Max file size exceeded!";
                 } else {
                     if ($_FILES['userFile']['error'] === UPLOAD_ERR_NO_FILE) {
                         $error = "You must choose a file!";
                     } else {
                         $error = "An unknown error occurred during upload!";
                     }
                 }
             }
             return $error;
         }
     }
 }
开发者ID:edwardshe,项目名称:sublite,代码行数:54,代码来源:ResumeUpload.php

示例3: MoveToS3

 /**
  * This moves a file from the local filesystem to the S3 file system provided in the tracmor_configuration.inc.php file
  *
  * @param string $strPath
  * @param string $strFileName
  * @param string $strType MIME type of the file
  * @param string $strS3Path path to S3 folder including leading slash- '/attachments' for example
  * @return bool
  */
 public static function MoveToS3($strPath, $strFileName, $strType, $strS3Path)
 {
     $strPath = rtrim($strPath, '/');
     $strS3Path = rtrim($strS3Path, '/');
     if (file_exists($strPath . '/' . $strFileName)) {
         require_once __DOCROOT__ . __PHP_ASSETS__ . '/S3.php';
         $objS3 = new S3(AWS_ACCESS_KEY, AWS_SECRET_KEY);
         // Put the file in S3
         $objS3->putObjectFile($strPath . '/' . $strFileName, AWS_BUCKET, ltrim(AWS_PATH, '/') . $strS3Path . '/' . $strFileName, S3::ACL_PUBLIC_READ);
         // Delete the temporary file from web server
         unlink($strPath . '/' . $strFileName);
         unset($objS3);
         return true;
     } else {
         return false;
     }
 }
开发者ID:jdellinger,项目名称:tracmor,代码行数:26,代码来源:QApplication.class.php

示例4: upload

 /**
  * Uploads files to FTP
  *
  * @param array $files
  * @param array $results
  * @param boolean $force_rewrite
  * @return boolean
  */
 function upload($files, &$results, $force_rewrite = false)
 {
     $count = 0;
     $error = null;
     if (!$this->_init($error)) {
         $results = $this->get_results($files, W3_CDN_RESULT_HALT, $error);
         return false;
     }
     foreach ($files as $local_path => $remote_path) {
         if (!file_exists($local_path)) {
             $results[] = $this->get_result($local_path, $remote_path, W3_CDN_RESULT_ERROR, 'Source file not found');
             continue;
         }
         if (!$force_rewrite) {
             $info = @$this->_s3->getObjectInfo($this->_config['bucket'], $remote_path);
             if ($info) {
                 $hash = @md5_file($local_path);
                 $s3_hash = isset($info['hash']) ? $info['hash'] : '';
                 if ($hash === $s3_hash) {
                     $results[] = $this->get_result($local_path, $remote_path, W3_CDN_RESULT_ERROR, 'Object already exists');
                     continue;
                 }
             }
         }
         $result = @$this->_s3->putObjectFile($local_path, $this->_config['bucket'], $remote_path, S3::ACL_PUBLIC_READ);
         $results[] = $this->get_result($local_path, $remote_path, $result ? W3_CDN_RESULT_OK : W3_CDN_RESULT_ERROR, $result ? 'OK' : 'Unable to put object');
         if ($result) {
             $count++;
         }
     }
     return $count;
 }
开发者ID:alx,项目名称:SBek-Arak,代码行数:40,代码来源:S3.php

示例5: put

 public function put($file, $name = null)
 {
     if (empty($name)) {
         $name = str_replace("\\", '/', str_replace(PHPFOX_DIR, '', $file));
     }
     return $this->_obj->putObjectFile($file, $this->_bucket, $name, \S3::ACL_PUBLIC_READ);
 }
开发者ID:mepsteinj,项目名称:phpfox-amazons3,代码行数:7,代码来源:CDN.php

示例6: onImageAddition

 public function onImageAddition(ImageAdditionEvent $event)
 {
     global $config;
     $access = $config->get_string("amazon_s3_access");
     $secret = $config->get_string("amazon_s3_secret");
     $bucket = $config->get_string("amazon_s3_bucket");
     if (!empty($bucket)) {
         log_debug("amazon_s3", "Mirroring Image #" . $event->image->id . " to S3 #{$bucket}");
         $s3 = new S3($access, $secret);
         $s3->putBucket($bucket, S3::ACL_PUBLIC_READ);
         $s3->putObjectFile(warehouse_path("thumbs", $event->image->hash), $bucket, 'thumbs/' . $event->image->hash, S3::ACL_PUBLIC_READ, array(), array("Content-Type" => "image/jpeg", "Content-Disposition" => "inline; filename=image-" . $event->image->id . ".jpg"));
         $s3->putObjectFile(warehouse_path("images", $event->image->hash), $bucket, 'images/' . $event->image->hash, S3::ACL_PUBLIC_READ, array(), array("Content-Type" => $event->image->get_mime_type(), "Content-Disposition" => "inline; filename=image-" . $event->image->id . "." . $event->image->ext));
     }
 }
开发者ID:nsuan,项目名称:shimmie2,代码行数:14,代码来源:main.php

示例7: uploadFile

 public function uploadFile($file, $path, $acl = S3::ACL_PUBLIC_READ, $save = true)
 {
     //is it a real file?
     if (file_exists($file)) {
         //do the actual upload.
         $s3 = new S3(AMAZON_AWS_KEY, AMAZON_AWS_SECRET);
         $result = $s3->putObjectFile($file, AMAZON_S3_BUCKET_NAME, $path, S3::ACL_PUBLIC_READ);
         //echo "Uploading {$file} to " . AMAZON_S3_BUCKET_NAME . ":{$path}\n";
         //get our info for saving
         $info = $s3->getObjectInfo(AMAZON_S3_BUCKET_NAME, $path, true);
         //save our info.
         $this->set('hash', $info['hash']);
         $this->set('size', $info['size']);
         $this->set('type', $info['type']);
         $this->set('bucket', AMAZON_S3_BUCKET_NAME);
         $this->set('path', $path);
         $this->set('add_date', date("Y-m-d H:i:s"));
         //for non db accessible scripts.
         if ($save) {
             $this->save();
         }
         //yay!
         if ($result !== false) {
             return true;
         }
     } else {
         echo "No file at {$path} or {$file}\n";
     }
     //fail!
     return false;
 }
开发者ID:ricberw,项目名称:BotQueue,代码行数:31,代码来源:s3file.php

示例8: upload

		function upload($localFilepath = 'path/to/file.jpg',$s3Path = 'tmp/', $filename = 'filename.jpg',$bucket = 'idc_files'){

			// $filename is the name that we want to save it as
			// - this is going to be something unique every time

			// Import Vendor file
			App::import('Vendor', 'S3', array('file' => 'S3'.DS.'s3.php'));

			// Instantiate the S3 class
			$s3 = new S3(AWS_ACCESS_KEY, AWS_SECRET_KEY); // defined in bootstrap.php

			// Ensure $newPath is valid
			if(substr($s3Path,-1,1) != '/'){
				$s3Path .= '/';
			}

			// Intended directory
			// - buckets are like the C: drive
			$intendedPath = $s3Path.$filename;

			// Put our file (also with public read access)
			if ($s3->putObjectFile($localFilepath, $bucket, $intendedPath, S3::ACL_PUBLIC_READ)) {
					//echo "S3::putObjectFile(): File copied to {$bucket}/".baseName($uploadFile).PHP_EOL;
					return 1;
			} else {
					return 0;
			}

			exit;   

		}
开发者ID:ryankanno,项目名称:Twilio-State-Machine,代码行数:31,代码来源:amazons3.php

示例9: isset

 /**
  * Uploads single file to S3
  *
  * @param array CDN file array
  * @param boolean $force_rewrite
  * @return array
  */
 function _upload($file, $force_rewrite = false)
 {
     $local_path = $file['local_path'];
     $remote_path = $file['remote_path'];
     if (!file_exists($local_path)) {
         return $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, 'Source file not found.');
     }
     if (!$force_rewrite) {
         $this->_set_error_handler();
         $info = @$this->_s3->getObjectInfo($this->_config['bucket'], $remote_path);
         $this->_restore_error_handler();
         if ($info) {
             $hash = @md5_file($local_path);
             $s3_hash = isset($info['hash']) ? $info['hash'] : '';
             if ($hash === $s3_hash) {
                 return $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_OK, 'Object up-to-date.');
             }
         }
     }
     $headers = $this->_get_headers($file);
     $this->_set_error_handler();
     $result = @$this->_s3->putObjectFile($local_path, $this->_config['bucket'], $remote_path, S3::ACL_PUBLIC_READ, array(), $headers);
     $this->_restore_error_handler();
     if ($result) {
         return $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_OK, 'OK');
     }
     return $this->_get_result($local_path, $remote_path, W3TC_CDN_RESULT_ERROR, sprintf('Unable to put object (%s).', $this->_get_last_error()));
 }
开发者ID:easinewe,项目名称:Avec2016,代码行数:35,代码来源:S3.php

示例10: grav_submit_to_s3

function grav_submit_to_s3($entry, $form)
{
    // no file?  no problem.
    if (empty($entry[GFORM_UPLOAD_FIELD_ID])) {
        return;
    }
    $gfs3 = new S3(awsAccessKey, awsSecretKey);
    // url of uploaded file
    $file_url = $entry[GFORM_UPLOAD_FIELD_ID];
    // filename of uploaded file
    $file_name = $_FILES['input_' . GFORM_UPLOAD_FIELD_ID]['name'];
    // ensure bucket is there
    $gfs3->putBucket(BUCKET_NAME, S3::ACL_AUTHENTICATED_READ);
    // clean up filename, split into parts
    $url_parts = parse_url($file_url);
    $full_path = $_SERVER['DOCUMENT_ROOT'] . substr($url_parts['path'], 1);
    if (is_dir($file_name)) {
        $file_name = basename($file_name);
    }
    // this is the full path to the file on S3
    $filename_to_s3 = UPLOAD_PATH . sanitize_file_name($file_name);
    if ($gfs3->putObjectFile($full_path, BUCKET_NAME, $filename_to_s3, S3::ACL_PUBLIC_READ)) {
        return true;
        // upload success
    } else {
        wp_die('It looks like something went wrong while uploading your file. Please try again in a few moments.');
    }
}
开发者ID:jpopgravitate,项目名称:grav-gforms-and-s3,代码行数:28,代码来源:gfs3.php

示例11: copy

 /**
  * Copy 
  * 
  * @param string $from        Full path
  * @param string $to          Short path
  * @param array  $httpHeaders HTTP headers OPTIONAL
  *  
  * @return boolean
  */
 public function copy($from, $to, array $httpHeaders = array())
 {
     $result = false;
     if (\Includes\Utils\FileManager::isExists($from)) {
         try {
             $result = $this->client->putObjectFile($from, \XLite\Core\Config::getInstance()->CDev->AmazonS3Images->bucket, $to, \S3::ACL_PUBLIC_READ, array(), $httpHeaders);
         } catch (\S3Exception $e) {
             $result = false;
             \XLite\Logger::getInstance()->registerException($e);
         }
     }
     return $result;
 }
开发者ID:kingsj,项目名称:core,代码行数:22,代码来源:S3.php

示例12: transfer

 /**
  * Transfer an object to the S3 storage bucket.
  *
  * @access public
  * @param string $path
  * @return string
  */
 public function transfer($path)
 {
     if ($this->s3 === null) {
         return $path;
     }
     $name = $this->s3->path . basename($path);
     $bucket = $this->s3->bucket;
     if ($this->s3->putObjectFile($this->uploader->formatPath($path), $bucket, $name, S3::ACL_PUBLIC_READ)) {
         $this->s3->uploads[] = $path;
         return sprintf('http://%s.%s/%s', $bucket, self::AS3_DOMAIN, $name);
     }
     return $path;
 }
开发者ID:robksawyer,项目名称:article,代码行数:20,代码来源:AttachmentBehavior.php

示例13: updateUserImage

 public static function updateUserImage($userId)
 {
     $result = new FunctionResult();
     $result->success = false;
     if (!empty($userId)) {
         $user = GameUsers::getGameUserById($userId);
         if (!empty($user)) {
             $tmpImgPath = UserProfileImageUtils::downloadFBProfileImage($user->facebookId);
             $profileImageUrl = null;
             if (!empty($tmpImgPath)) {
                 try {
                     $s3 = new S3(AWS_API_KEY, AWS_SECRET_KEY);
                     $s3->setEndpoint(AWS_S3_ENDPOINT);
                     $imageName = "pi_" . $userId . ".png";
                     $s3Name = "profile.images/" . $userId . "/" . $imageName;
                     $res = $s3->putObjectFile($tmpImgPath, AWS_S3_BUCKET, $s3Name, S3::ACL_PUBLIC_READ);
                     if ($res) {
                         $profileImageUrl = 'http://' . AWS_S3_BUCKET . '.s3.amazonaws.com/' . $s3Name;
                         try {
                             unlink($tmpImgPath);
                         } catch (Exception $exc) {
                             error_log($exc->getTraceAsString());
                         }
                     } else {
                         $result->result = json_encode($res);
                     }
                 } catch (Exception $exc) {
                     $result->result = $exc->getTraceAsString();
                 }
             } else {
                 $profileImageUrl = USER_DEFAULT_IMAGE_URL;
             }
             if (!empty($profileImageUrl)) {
                 $user->setProfilePicture($profileImageUrl);
                 try {
                     $user->updateToDatabase(DBUtils::getConnection());
                     $result->success = true;
                     $result->result = null;
                 } catch (Exception $exc) {
                     $result->result = $exc->getTraceAsString();
                 }
             }
         } else {
             $result->result = "user not found";
         }
     } else {
         $result->result = "user id empty";
     }
     return $result;
 }
开发者ID:bsormagec,项目名称:tavlamania-php,代码行数:50,代码来源:UserProfileImageFunctions.php

示例14: upload

 public function upload()
 {
     if (!empty($this->_upload_dir)) {
         $this->_bucket_name .= $this->_bucket_name . '/' . $this->_upload_dir;
     }
     // アマゾンS3のインスタンス生成
     $s3 = new S3($this->_access_key, $this->_secret_key);
     if (!$s3) {
         throw new Teamlab_Batch_Exception(sprintf("AWS接続に失敗しました。: %s", $this->_bucket_name));
     }
     // ファイルアップロード
     if ($s3->putObjectFile($this->_upload_file, $this->_bucket_name, baseName($this->_upload_file), S3::ACL_PUBLIC_READ)) {
         return true;
     } else {
         throw new Teamlab_Batch_Transport_Exception(sprintf("ファイルのアップロードに失敗しました。サーバ情報:%s ファイル名:%s", $this->_bucket_name, baseName($this->_upload_file)));
     }
 }
开发者ID:qpzm7913,项目名称:batch,代码行数:17,代码来源:S3.php

示例15: _upToS3

 protected function _upToS3($id, array $files)
 {
     $s3 = $this->config->item('s3');
     if (!$s3) {
         throw new Exception("Error Processing Request", 1);
     }
     $this->load->library('S3');
     $s3 = new S3();
     $bucket = $this->config->item('bucket');
     foreach ($files as $key => $value) {
         if ($s3->putObjectFile($config['upload_path'] . DIRECTORY_SEPARATOR . $key . '_' . $value['file_name'], $bucket, $directory . DIRECTORY_SEPARATOR . 'photo' . DIRECTORY_SEPARATOR . $id . DIRECTORY_SEPARATOR . $key . '_' . $value['file_name'], S3::ACL_PUBLIC_READ)) {
             //echo "We successfully uploaded your file.";
         } else {
             //echo "Something went wrong while uploading your file... sorry.";
         }
     }
 }
开发者ID:sleeping-lion,项目名称:slboard_codeigniter,代码行数:17,代码来源:SL_Photo.php


注:本文中的S3::putObjectFile方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。