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


PHP S3::inputFile方法代码示例

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


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

示例1: upload_image

 public function upload_image()
 {
     $config = array('allowed_types' => 'jpg|jpeg|gif|png', 'upload_path' => './temp', 'max_size' => 3072, 'overwrite' => true);
     $this->load->library('upload', $config);
     $this->upload->overwrite = true;
     $response['responseStatus'] = "Not OK";
     if (!$this->upload->do_upload()) {
         $response['responseStatus'] = "Your image could not be uploaded";
     } else {
         $data = $this->upload->data();
         //instantiate the class
         $s3 = new S3(awsAccessKey, awsSecretKey);
         $ext = pathinfo($data['full_path'], PATHINFO_EXTENSION);
         $imgName = (string) time() . "." . $ext;
         $input = S3::inputFile($data['full_path'], FALSE);
         if ($s3->putObject(file_get_contents($data['full_path']), "tlahui-content", $imgName, S3::ACL_PUBLIC_READ)) {
             $response['responseStatus'] = "OK";
             $response['url'] = "https://s3.amazonaws.com/tlahui-content/" . $imgName;
             unlink($data['full_path']);
         } else {
             $response['responseStatus'] = "Your image could not be uploaded";
             unlink($data['full_path']);
         }
     }
     echo json_encode($response);
 }
开发者ID:mvalenciarmz,项目名称:PagosElectronicos-Upload,代码行数:26,代码来源:upload.php

示例2: execute

 /**
  * Execute the controller.
  *
  * @return  mixed Return executed result.
  *
  * @throws  \LogicException
  * @throws  \RuntimeException
  */
 public function execute()
 {
     $files = $this->input->files;
     $field = $this->input->get('field', 'file');
     $type = $this->input->get('type', 'post');
     try {
         $src = $files->getByPath($field . '.tmp_name', null, InputFilter::STRING);
         $name = $files->getByPath($field . '.name', null, InputFilter::STRING);
         if (!$src) {
             throw new \Exception('File not upload');
         }
         $dest = $this->getDest($name, $type);
         $s3 = new \S3($this->app->get('amazon.access_key'), $this->app->get('amazon.secret_key'));
         $result = $s3::putObject(\S3::inputFile($src, false), 'windspeaker', $dest, \S3::ACL_PUBLIC_READ);
         if (!$result) {
             throw new \Exception('Upload fail.');
         }
     } catch (\Exception $e) {
         $response = new Response();
         $response->setBody(json_encode(['error' => $e->getMessage()]));
         $response->setMimeType('text/json');
         $response->respond();
         exit;
     }
     $return = new Registry();
     $return['filename'] = 'https://windspeaker.s3.amazonaws.com/' . $dest;
     $return['file'] = 'https://windspeaker.s3.amazonaws.com/' . $dest;
     $response = new Response();
     $response->setBody((string) $return);
     $response->setMimeType('text/json');
     $response->respond();
     exit;
 }
开发者ID:Trult,项目名称:windspeaker-demo,代码行数:41,代码来源:SaveController.php

示例3: upload

 /**
  * upload
  *
  * @param \JInput    $input
  */
 public static function upload(\JInput $input)
 {
     try {
         $editorPlugin = \JPluginHelper::getPlugin('editors', 'akmarkdown');
         if (!$editorPlugin) {
             throw new \Exception('Editor Akmarkdown not exists');
         }
         $params = new Registry($editorPlugin->params);
         $files = $input->files;
         $field = $input->get('field', 'file');
         $type = $input->get('type', 'post');
         $allows = $params->get('Upload_AllowExtension', '');
         $allows = array_map('strtolower', array_map('trim', explode(',', $allows)));
         $file = $files->getVar($field);
         $src = $file['tmp_name'];
         $name = $file['name'];
         $tmp = new \SplFileInfo(JPATH_ROOT . '/tmp/ak-upload/' . $name);
         if (empty($file['tmp_name'])) {
             throw new \Exception('File not upload');
         }
         $ext = pathinfo($name, PATHINFO_EXTENSION);
         if (!in_array($ext, $allows)) {
             throw new \Exception('File extension now allowed.');
         }
         // Move file to tmp
         if (!is_dir($tmp->getPath())) {
             \JFolder::create($tmp->getPath());
         }
         if (is_file($tmp->getPathname())) {
             \JFile::delete($tmp->getPathname());
         }
         \JFile::upload($src, $tmp->getPathname());
         $src = $tmp;
         $dest = static::getDest($name, $params->get('Upload_S3_Subfolder', 'ak-upload'));
         $s3 = new \S3($params->get('Upload_S3_Key'), $params->get('Upload_S3_SecretKey'));
         $bucket = $params->get('Upload_S3_Bucket');
         $result = $s3::putObject(\S3::inputFile($src->getPathname(), false), $bucket, $dest, \S3::ACL_PUBLIC_READ);
         if (is_file($tmp->getPathname())) {
             \JFile::delete($tmp->getPathname());
         }
         if (!$result) {
             throw new \Exception('Upload fail.');
         }
     } catch (\Exception $e) {
         $response = new Response();
         $response->setBody(json_encode(['error' => $e->getMessage()]));
         $response->setMimeType('text/json');
         $response->respond();
         exit;
     }
     $return = new \JRegistry();
     $return['filename'] = 'https://' . $bucket . '.s3.amazonaws.com/' . $dest;
     $return['file'] = 'https://' . $bucket . '.s3.amazonaws.com/' . $dest;
     $response = new Response();
     $response->setBody((string) $return);
     $response->setMimeType('text/json');
     $response->respond();
 }
开发者ID:lyrasoft,项目名称:lyrasoft.github.io,代码行数:63,代码来源:ImageUploader.php

示例4: create

 function create($localpath, $remotepath)
 {
     $localpath = realpath($localpath);
     if (S3::putObject(S3::inputFile($localpath), $this->backupBucket, $remotepath, S3::ACL_PRIVATE)) {
         return TRUE;
     } else {
         return FALSE;
     }
 }
开发者ID:pcisneros,项目名称:glab-ci-ext,代码行数:9,代码来源:S3_Backup.php

示例5: save_sized_image

 function save_sized_image($original, $key, $size, $folder)
 {
     $file = $folder . "/" . $key . ".jpg";
     $file_path = IMAGES_DIR . "/" . $file;
     resize_image($original, $size, $file_path);
     if (STORAGE_STRATEGY == 's3') {
         $input = S3::inputFile($file_path);
         S3::putObject($input, S3_BUCKET, $file, S3::ACL_PUBLIC_READ);
     }
 }
开发者ID:schlos,项目名称:electionleaflets,代码行数:10,代码来源:image_que.php

示例6: action_create

 /**
  * CRUD controller: CREATE
  */
 public function action_create()
 {
     $this->auto_render = FALSE;
     $this->template = View::factory('js');
     if (!isset($_FILES['image'])) {
         $this->template->content = json_encode('KO');
         return;
     }
     $image = $_FILES['image'];
     if (core::config('image.aws_s3_active')) {
         require_once Kohana::find_file('vendor', 'amazon-s3-php-class/S3', 'php');
         $s3 = new S3(core::config('image.aws_access_key'), core::config('image.aws_secret_key'));
     }
     if (!Upload::valid($image) or !Upload::not_empty($image) or !Upload::type($image, explode(',', core::config('image.allowed_formats'))) or !Upload::size($image, core::config('image.max_image_size') . 'M')) {
         if (Upload::not_empty($image) and !Upload::type($image, explode(',', core::config('image.allowed_formats')))) {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not valid format, please use one of this formats "%s"'), core::config('image.allowed_formats'))));
             return;
         }
         if (!Upload::size($image, core::config('image.max_image_size') . 'M')) {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . sprintf(__('Is not of valid size. Size is limited to %s MB per image'), core::config('image.max_image_size'))));
             return;
         }
         $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
         return;
     } elseif ($image != NULL) {
         // saving/uploading img file to dir.
         $path = 'images/cms/';
         $root = DOCROOT . $path;
         //root folder
         $image_name = URL::title(pathinfo($image['name'], PATHINFO_FILENAME));
         $image_name = Text::limit_chars(URL::title(pathinfo($image['name'], PATHINFO_FILENAME)), 200);
         $image_name = time() . '.' . $image_name;
         // if folder does not exist, try to make it
         if (!file_exists($root) and !@mkdir($root, 0775, true)) {
             // mkdir not successful ?
             $this->template->content = json_encode(array('msg' => __('Image folder is missing and cannot be created with mkdir. Please correct to be able to upload images.')));
             return;
             // exit function
         }
         // save file to root folder, file, name, dir
         if ($file = Upload::save($image, $image_name, $root)) {
             // put image to Amazon S3
             if (core::config('image.aws_s3_active')) {
                 $s3->putObject($s3->inputFile($file), core::config('image.aws_s3_bucket'), $path . $image_name, S3::ACL_PUBLIC_READ);
             }
             $this->template->content = json_encode(array('link' => Core::config('general.base_url') . $path . $image_name));
             return;
         } else {
             $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image file could not been saved.')));
             return;
         }
         $this->template->content = json_encode(array('msg' => $image['name'] . ' ' . __('Image is not valid. Please try again.')));
     }
 }
开发者ID:JeffPedro,项目名称:project-garage-sale,代码行数:57,代码来源:cmsimages.php

示例7: UploadToCloud

 function UploadToCloud($file_source, $model_id, $model_name, $type, $mime_type, $file_ext = null)
 {
     App::import('Vendor', 'S3', array('file' => 'S3.php'));
     $s3 = new S3($this->awsAccessKey, $this->awsSecretKey, true, "s3-ap-southeast-1.amazonaws.com");
     $input = $s3->inputFile($file_source, false);
     $ext = pathinfo($file_source, PATHINFO_EXTENSION);
     if ($file_ext != null) {
         $obj = $s3->putObject($input, $this->bucketName, "contents/" . $model_name . "/" . $model_id . "/" . $model_id . "_" . $type . "." . $file_ext, S3::ACL_PUBLIC_READ, array(), array("Content-Type" => $mime_type));
     } else {
         $obj = $s3->putObject($input, $this->bucketName, "contents/" . $model_name . "/" . $model_id . "/" . $model_id . "_" . $type . "." . $ext, S3::ACL_PUBLIC_READ, array(), array("Content-Type" => $mime_type));
     }
     return $obj;
 }
开发者ID:koprals,项目名称:coda-gosales-hsbc,代码行数:13,代码来源:GeneralComponent.php

示例8: gsUpload

function gsUpload($file, $bucket, $remoteFile)
{
    $ret = false;
    $key = 'GOOGT4X7CFTWS2VWN2HT';
    $secret = 'SEWZTyKZH6dNbjbT2CHg5Q5pUh5Y5+iinj0yBFB4';
    $server = 'storage.googleapis.com';
    $s3 = new S3($key, $secret, false, $server);
    $metaHeaders = array();
    $requestHeaders = array();
    if ($s3->putObject($s3->inputFile($file, false), $bucket, $remoteFile, S3::ACL_PUBLIC_READ, $metaHeaders, $requestHeaders)) {
        $ret = true;
    }
    return $ret;
}
开发者ID:risyasin,项目名称:webpagetest,代码行数:14,代码来源:gstest.php

示例9: S3copy

 private function S3copy($file)
 {
     $fileok = true;
     $s3 = new S3($this->AccessKey, $this->SecretKey);
     $list = $s3->getBucket($this->AWSFolder);
     foreach ($list as $existing) {
         if ($existing['name'] === $file) {
             $fileok = false;
         }
     }
     if ($fileok) {
         $put = $s3->putObject($s3->inputFile(ASSETS_PATH . DIRECTORY_SEPARATOR . $file), $this->AWSFolder, $file, S3::ACL_PRIVATE);
         if ($put) {
             echo $file . " transferred to S3<br>" . "\r\n";
         } else {
             echo $file . " unable to be transferred to S3<br>" . "\r\n";
         }
     } else {
         echo $file . " already in S3<br>" . "\r\n";
     }
 }
开发者ID:spark-green,项目名称:silverstripe-aws-s3-backup,代码行数:21,代码来源:S3Backup.php

示例10: upload

    function upload($path)
    {
        $access = DB::get()->assoc("SELECT name, value FROM options WHERE grouping = 'Amazon Web Services'");
        $s3 = new S3($access['AWS Access Key ID'], $access['AWS Secret Access Key']);
        $bucketname = $access['S3 Bucket Name'];
        $filename = $_FILES['uploaded']['name'];
        $s3filename = $this->_safestring(Auth::user()->username) . '/' . date('YmdHis') . '/' . $filename;
        preg_match('%\\.(\\w+)$%', $filename, $matches);
        $filetype = $matches[1];
        $s3->putObject(S3::inputFile($_FILES['uploaded']['tmp_name']), $bucketname, $s3filename, S3::ACL_PUBLIC_READ, array(), array("Content-Type" => "application/octet-stream", "Content-Disposition" => "attachment; filename=" . urlencode($filename) . ';'));
        //echo "Put {$filename} to {$bucketname} at {$s3filename}\n";
        $url = "http://{$bucketname}.s3.amazonaws.com/{$s3filename}";
        DB::get()->query("INSERT INTO files (user_id, filename, filesize, filetype, url) VALUES (:user_id, :filename, :filesize, :filetype, :url);", array('user_id' => Auth::user_id(), 'filename' => $filename, 'filesize' => $_FILES['uploaded']['size'], 'filetype' => $filetype, 'url' => $url));
        $filenumber = DB::get()->lastInsertId();
        echo <<<RELOAD_FILES
atbottom = isVisible(\$('#notices tr:last-child'));
\$('#filelisting').load('/files/filelist', function(){
\t\$('body').css('margin-bottom', \$('#command').height() + 15);
\tdo_scroll();
});
send('/file {$filenumber}');
RELOAD_FILES;
    }
开发者ID:amitchouhan004,项目名称:barchat,代码行数:23,代码来源:files.php

示例11: time

                $height = "512";
                $isAudio = true;
                $mediaType = 3;
            }
        }
    }
}
$md5filename = md5(str_replace(" ", "_", str_replace(".", "", $filename)) . "cometchat" . time());
if ($isImage || $isVideo) {
    $md5filename .= "." . strtolower($path['extension']);
}
$unencryptedfilename = rawurlencode($filename);
if (defined('AWS_STORAGE') && AWS_STORAGE == '1' && !empty($_FILES['Filedata'])) {
    include_once dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . "functions" . DIRECTORY_SEPARATOR . "storage" . DIRECTORY_SEPARATOR . "s3.php";
    $s3 = new S3(AWS_ACCESS_KEY, AWS_SECRET_KEY);
    if (!$s3->putObject($s3->inputFile($_FILES['Filedata']['tmp_name'], false), AWS_BUCKET, $bucket_path . 'filetransfer/' . $md5filename, S3::ACL_PUBLIC_READ)) {
        $error = 1;
    }
    $linkToFile = '//' . $aws_bucket_url . '/' . $bucket_path . 'filetransfer/' . $md5filename;
    $server_url = BASE_URL;
} else {
    if (!empty($_FILES['Filedata']) && is_uploaded_file($_FILES['Filedata']['tmp_name'])) {
        if (!move_uploaded_file($_FILES['Filedata']['tmp_name'], dirname(dirname(dirname(__FILE__))) . DIRECTORY_SEPARATOR . 'writable' . DIRECTORY_SEPARATOR . 'filetransfer' . DIRECTORY_SEPARATOR . 'uploads' . DIRECTORY_SEPARATOR . $md5filename)) {
            $error = 1;
        }
        $linkToFile = BASE_URL . "writable/filetransfer/uploads/" . $md5filename;
        $server_url = '//' . $_SERVER['SERVER_NAME'] . BASE_URL;
        if (filter_var(BASE_URL, FILTER_VALIDATE_URL)) {
            $server_url = BASE_URL;
        }
    }
开发者ID:albertoneto,项目名称:localhost,代码行数:31,代码来源:upload.php

示例12: cache_me

 function cache_me($params, $content_type)
 {
     global $PREFS, $TMPL;
     // Set URL constants
     if (is_readable($params['full_src']) || strstr($params['full_src'], 'http://') || strstr($params['full_src'], 'https://')) {
         $original = file_get_contents($params['full_src']);
     } else {
         $file_url = "http";
         if (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] == "on") {
             $file_url .= "s";
         }
         $file_url .= "://www." . $_SERVER['HTTP_HOST'] . $params['src'];
         file_get_contents($file_url);
     }
     $filename = basename($params['src']);
     $cache_structure = pathinfo($params['cache_src']);
     $cache_dirname = $cache_structure['dirname'];
     $cache_basename = $cache_structure['basename'];
     $cache_filename = $cache_structure['filename'];
     // Create Cache Dir if it does not exist
     if (!is_dir($cache_dirname)) {
         if (!mkdir($cache_dirname, 0777, true)) {
             error_log("I did not write the cache dir");
         }
     }
     if (!defined("FILE_PUT_CONTENTS_ATOMIC_TEMP")) {
         define("FILE_PUT_CONTENTS_ATOMIC_TEMP", $cache_dirname);
     }
     if (!defined("FILE_PUT_CONTENTS_ATOMIC_MODE")) {
         define("FILE_PUT_CONTENTS_ATOMIC_MODE", 0777);
     }
     if (!defined("FILE_PUT_CONTENTS_ATOMIC_OWN")) {
         define("FILE_PUT_CONTENTS_ATOMIC_OWN", 'deploy');
     }
     $temp = tempnam(FILE_PUT_CONTENTS_ATOMIC_TEMP, 'temp');
     if (!($f = @fopen($temp, 'wb'))) {
         $temp = FILE_PUT_CONTENTS_ATOMIC_TEMP . DIRECTORY_SEPARATOR . uniqid('temp');
         if (!($f = @fopen($temp, 'wb'))) {
             trigger_error("file_put_contents_atomic() : error writing temporary file '{$temp}'", E_USER_WARNING);
             return false;
         }
     }
     // Check to see if its a parsed CSS file, if so write the parsed data
     if (!empty($params['cssfile_content'])) {
         fwrite($f, $params['cssfile_content']);
     } else {
         fwrite($f, $original);
     }
     fclose($f);
     if (!@rename($temp, $params['cache_src'])) {
         @unlink($params['cache_src']);
         @rename($temp, $params['cache_src']);
     }
     //AWS access info - Make sure to add this to your config.php file
     $s3assetsConfig = $PREFS->core_ini['s3assets'];
     if (isset($s3assetsConfig['user'])) {
         if (!defined("FILE_PUT_CONTENTS_ATOMIC_OWN")) {
             define("FILE_PUT_CONTENTS_ATOMIC_OWN", $s3assetsConfig['user']);
         }
         chown($params['cache_src'], FILE_PUT_CONTENTS_ATOMIC_OWN);
     }
     chmod($params['cache_src'], FILE_PUT_CONTENTS_ATOMIC_MODE);
     // Initiate S3 class and upload the file
     if ($params['s3bucket'] != "") {
         if (!class_exists('S3')) {
             require_once 'pi.s3assets/S3.php';
         }
         $awsAccessKey = $s3assetsConfig['awsAccessKey'];
         $awsSecretKey = $s3assetsConfig['awsSecretKey'];
         if (!defined('awsAccessKey')) {
             define('awsAccessKey', $awsAccessKey);
         }
         if (!defined('awsSecretKey')) {
             define('awsSecretKey', $awsSecretKey);
         }
         $s3 = new S3(awsAccessKey, awsSecretKey, false);
         if (isset($params['s3assetname'])) {
             $src = preg_replace("/^\\//", "", $params['s3assetname']);
         } else {
             $src = preg_replace("/^\\//", "", $params['src']);
         }
         S3::putObject(S3::inputFile($params['cache_src']), $params['s3bucket'], $src, S3::ACL_PUBLIC_READ, array(), array("Content-Type" => $content_type, "Cache-Control" => "max-age=315360000", "Expires" => gmdate("D, d M Y H:i:s T", strtotime("+5 years"))));
     }
 }
开发者ID:joshjensen,项目名称:s3assets,代码行数:84,代码来源:pi.s3assets.php

示例13: cron_aws

 function cron_aws($aws_accesskey, $aws_secretkey, $aws_bucket, $aws_directory, $file, $delete_after_int = 0)
 {
     $details = '';
     $details .= "AWS Access Key: " . $aws_accesskey . "\n";
     if ($this->_debug) {
         $details .= "AWS Secret Key: " . $aws_secretkey . "\n";
     } else {
         $details .= "AWS Secret Key: *hidden*\n";
     }
     $details .= "AWS Bucket: " . $aws_bucket . "\n";
     $details .= "AWS Directory: " . $aws_directory . "\n";
     $details .= "Local File & Path: " . $this->_options['backup_directory'] . '/' . basename($file) . "\n";
     $details .= "Filename: " . basename($file) . "\n";
     $this->log('Starting Amazon S3 cron. Details: ' . $details);
     require_once dirname(__FILE__) . '/lib/s3/s3.php';
     $s3 = new S3($aws_accesskey, $aws_secretkey);
     if ($this->_options['aws_ssl'] != '1') {
         S3::$useSSL = false;
     }
     $this->log('About to put bucket to Amazon S3 cron.');
     $s3->putBucket($aws_bucket, S3::ACL_PUBLIC_READ);
     $this->log('About to put object (the file) to Amazon S3 cron.');
     if ($s3->putObject(S3::inputFile($file), $aws_bucket, $aws_directory . '/' . basename($file), S3::ACL_PRIVATE)) {
         // success
         $this->log('SUCCESS sending to Amazon S3!');
     } else {
         $this->mail_notice('ERROR #9002! Failed sending file to Amazon S3. Details:' . "\n\n" . $details);
         $this->log('FAILURE sending to Amazon S3! Details: ' . $details, 'error');
     }
     if ($delete_after_int == 1) {
         $this->log('Deleting backup file after Amazon S3 cron.');
         unlink($file);
         $this->log('Done deleting backup file after Amazon S3 cron.');
     }
 }
开发者ID:niko-lgdcom,项目名称:archives,代码行数:35,代码来源:backupbuddy.php

示例14: file_handleInput

function file_handleInput($Field, $Input, $FieldType, $Config, $predata)
{
    if (strtolower($Config['Content']['_ViewMode']) == 'api') {
        if (!empty($_FILES[$Field]['size'])) {
            $_FILES['dataForm']['name'][$Config['ID']][$Field] = $_FILES[$Field]['name'];
            $_FILES['dataForm']['size'][$Config['ID']][$Field] = $_FILES[$Field]['size'];
            $_FILES['dataForm']['tmp_name'][$Config['ID']][$Field] = $_FILES[$Field]['tmp_name'];
        }
    }
    if ($FieldType == 'multi') {
        return $Input;
    }
    if (!empty($_POST['deleteImage'][$Field])) {
        $FileInfo = explode('?', $predata[$Field]);
        if (file_exists($FileInfo[0])) {
            unlink($FileInfo[0]);
        }
        return '';
    }
    if (empty($_FILES['dataForm']['name'][$Config['ID']][$Field])) {
        return $predata[$Field];
    }
    // Create Directorys
    if (!empty($_FILES['dataForm']['size'][$Config['ID']][$Field])) {
        $path = wp_upload_dir();
        // set filename and paths
        $Ext = pathinfo($_FILES['dataForm']['name'][$Config['ID']][$Field]);
        $newFileName = uniqid($Config['ID'] . '_') . '.' . $Ext['extension'];
        $newLoc = $path['path'] . '/' . $newFileName;
        //$urlLoc = $path['url'].'/'.$newFileName;
        $GLOBALS['UploadedFile'][$Field] = $newLoc;
        $upload = wp_upload_bits($_FILES['dataForm']['name'][$Config['ID']][$Field], null, file_get_contents($_FILES['dataForm']['tmp_name'][$Config['ID']][$Field]));
        if (!empty($Config['Content']['_filesToLibrary'])) {
            global $user_ID;
            $type = wp_check_filetype($upload['file']);
            $new_post = array('post_title' => $Ext['filename'], 'post_status' => 'inherit', 'post_date' => date('Y-m-d H:i:s'), 'post_author' => $user_ID, 'post_type' => 'attachment', 'post_mime_type' => $type['type'], 'guid' => $upload['url']);
            // This should never be set as it would then overwrite an existing attachment.
            if (isset($attachment['ID'])) {
                unset($attachment['ID']);
            }
            // Save the data
            //$id = wp_insert_attachment($new_post, $upload['file']);
            //if ( !is_wp_error($id) ) {
            //    if(!function_exists('wp_generate_attachment_metadata')){
            //require_once('includes/image.php');
            //    }
            //wp_update_attachment_metadata( $id, wp_generate_attachment_metadata( $id, $upload['file'] ) );
            //}
        }
        //move_uploaded_file($_FILES['dataForm']['tmp_name'][$Config['ID']][$Field], $newLoc);
        //return $newLoc;
        if ($FieldType == 'image') {
            $imageWidth = $Config['Content']['_ImageSizeX'][$Field] == 'auto' ? '0' : $Config['Content']['_ImageSizeX'][$Field];
            $imageHeight = $Config['Content']['_ImageSizeY'][$Field] == 'auto' ? '0' : $Config['Content']['_ImageSizeY'][$Field];
            $iconWidth = $Config['Content']['_IconSizeX'][$Field] == 'auto' ? '0' : $Config['Content']['_IconSizeX'][$Field];
            $iconHeight = $Config['Content']['_IconSizeY'][$Field] == 'auto' ? '0' : $Config['Content']['_IconSizeY'][$Field];
            // crunch sizes
            $image = image_resize($upload['file'], $imageWidth, $imageHeight, true);
            $icon = image_resize($upload['file'], $iconWidth, $iconHeight, true);
        }
        //vardump($upload);
        //vardump($Config['Content']['_AWSBucket']);
        //die;
        if (!empty($Config['Content']['_enableS3'][$Field]) && !empty($Config['Content']['_AWSAccessKey'][$Field]) && !empty($Config['Content']['_AWSSecretKey'][$Field])) {
            include_once DB_TOOLKIT . 'data_form/fieldtypes/file/s3.php';
            $s3 = new S3($Config['Content']['_AWSAccessKey'][$Field], $Config['Content']['_AWSSecretKey'][$Field]);
            $input = $s3->inputFile($upload['file']);
            $fileName = date('Y') . '/' . date('m') . '/' . $newFileName;
            if ($s3->putObject($input, $Config['Content']['_AWSBucket'][$Field], $fileName, 'public-read')) {
                unlink($upload['file']);
                return $fileName;
            }
        }
        return $upload['url'];
    }
}
开发者ID:routexl,项目名称:DB-Toolkit,代码行数:76,代码来源:functions.php

示例15: publish_to_s3

 /**
  * Publish to AWS S3 bucket
  *
  * @return boolean|WP_Error
  */
 public function publish_to_s3($bucket, $aws_access_key_id, $aws_secret_access_key)
 {
     $directory_iterator = new RecursiveDirectoryIterator($this->archive_dir, RecursiveDirectoryIterator::SKIP_DOTS);
     $recursive_iterator = new RecursiveIteratorIterator($directory_iterator, RecursiveIteratorIterator::SELF_FIRST);
     S3::$useExceptions = true;
     $s3 = new S3($aws_access_key_id, $aws_secret_access_key, false, 's3-eu-west-1.amazonaws.com');
     foreach ($recursive_iterator as $item) {
         if (!$item->isDir()) {
             $path = $recursive_iterator->getSubPathName();
             try {
                 $s3->putObject(S3::inputFile($item->getRealPath()), $bucket, $path, S3::ACL_PUBLIC_READ);
             } catch (any $err) {
                 return new WP_Error('cannot_publish_to_s3', sprintf(__("Could not publish file to S3: %s: %s", $this->slug, $err), $path));
             }
         }
     }
     return true;
 }
开发者ID:kennu,项目名称:simply-static-s3,代码行数:23,代码来源:class-simply-static-archive-creator.php


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