public static function delete($file) { if (empty($file)) { return false; } if (function_exists('option')) { $bucket = option('config.attachment_up_bucket'); $user = option('config.attachment_up_username'); $pwd = option('config.attachment_up_password'); $unlink = option('config.attachment_upload_unlink'); } else { $bucket = C('config.attachment_up_bucket'); $user = C('config.attachment_up_username'); $pwd = C('config.attachment_up_password'); $unlink = C('config.attachment_upload_unlink'); } if (empty($bucket) || empty($user) || empty($pwd)) { return false; } if (empty($unlink)) { return false; } $upyun = new UpYun($bucket, $user, $pwd); try { error_log('upyunUser::delete:' . $file); $upyun->delete($file); } catch (Exception $e) { print_r($e); } }
/** * undocumented function * * @return void * @author apple **/ function wtImage($filename, $data, $type = null) { $upyun = new UpYun('liunian-photo', '', ''); $type = is_null($type) ? 'image' : 'avatar'; $dir = is_null($type) ? '/img/' : '/avatar/'; switch ($type) { case 'image': $year = date('Y'); $month = date('m'); $path = "{$dir}{$year}/{$month}/{$filename}"; break; case 'avatar': $path = $dir . $filename; break; default: } // echo $data;exit; try { $rsp = $upyun->writeFile($path, $data, True); return TRUE; } catch (Exception $e) { return FALSE; // return $e->getCode().$e->getMessage(); } }
public function show() { $sql = 'SELECT * FROM ' . DB_PREFIX . 'delete_file '; $orderby = ' ORDER BY create_time ASC'; $limit = ' limit 0, 1'; $data = $this->db->query_first($sql . $orderby . $limit); if ($data['bucket_name'] && $data['file_path']) { $upyun = new UpYun($data['bucket_name'], SPACEOPERATORS, SPACEOPERATORSPASSWORD); if ($upyun->delete($data['file_path']) === true) { $this->db->query('DELETE FROM ' . DB_PREFIX . 'delete_file WHERE id = ' . $data['id']); } else { $this->db->query('UPDATE ' . DB_PREFIX . 'delete_file SET times=times-1,create_time=' . TIMENOW . ' WHERE id = ' . $data['id']); } } $this->db->query('DELETE FROM ' . DB_PREFIX . 'delete_file where times<=0'); }
function upload($file, $path) { if (!empty($file) && !empty($path)) { require_once 'upyun.class.php'; $upyun = new UpYun($this->bucket, $this->username, $this->password); try { $fh = fopen($file, 'rb'); $return = $upyun->writeFile($path, $fh, TRUE); fclose($fh); return $this->domain . $path; } catch (Exception $e) { //echo $e->getCode(); //echo $e->getMessage(); } } return FALSE; }
private function upload2upyun($file, $fileName) { // 上传到upyun $upyun = new UpYun(Typecho_Widget::widget('Widget_Options')->plugin('UEditor')->upyun_bucket, Typecho_Widget::widget('Widget_Options')->plugin('UEditor')->upyun_user, Typecho_Widget::widget('Widget_Options')->plugin('UEditor')->upyun_password); try { $fn = fopen($file, 'rb'); $rsp = $upyun->writeFile($fileName, $fn, True); fclose($fn); if ($rsp) { $this->stateInfo = $this->stateMap[0]; } else { $this->stateInfo = $this->getStateInfo("ERROR_UPYUN"); return false; } } catch (Exception $e) { $this->stateInfo = $this->getCode(); return false; } }
public function upload($file, $file_path) { require_once dirname(__FILE__) . '/../../../common/upyun.class.php'; $upyun = new UpYun('app-tools', 'apirl', 'pestalia'); if (is_file($file) && file_exists($file)) { try { echo "=========准备上传文件" . $file_path . "\r\n"; echo "=========设置MD5校验文件完整性\r\n"; $opts = array(UpYun::CONTENT_MD5 => md5(file_get_contents($file))); $fh = fopen($file, 'rb'); $rsp = $upyun->writeFile($file_path, $fh, True, $opts); fclose($fh); var_dump($rsp); echo "=========DONE\r\n\r\n"; } catch (Exception $e) { echo $e->getCode(); echo $e->getMessage(); } } }
/** * 把微信的图片上传到又拍云服务器上 * @param string $medil * @return string */ public function updateWxImage($medil) { if (substr($medil, 0, 4) == 'http') { return $medil; } $accesstoken = WX::actionAccessToken(); $imgurl = "https://api.weixin.qq.com/cgi-bin/media/get?access_token={$accesstoken}&media_id={$medil}"; $upyun = new UpYun(UPYUN_BUCKET, UPYUN_USER, UPYUN_PASSWORD); $fh = file_get_contents($imgurl); if (empty($fh)) { return ""; } $md5 = md5($this->openid); $path = "/" . substr($md5, 0, 4) . '/' . $md5 . '/' . $medil . '.jpg'; $rsp = $upyun->writeFile($path, $fh, True); // 上传图片,自动创建目录 return UPYUN_CDN . $path; }
protected function _sendImageToYunServer($uploadList) { $upConf = C('upload'); if ($uploadList && $upConf['yun']['open']) { //开启云存储 T('image/upyun'); foreach ($uploadList as $key => $val) { try { $upyun = new UpYun($upConf['yun']['bucket'], $upConf['yun']['user'], $upConf['yun']['pwd']); $uploadList[$key]['savepath'] = $upConf['yun']['dir'] . ltrim($val['savepath'], $upConf['dir']); // z($uploadList[$key]['savepath']); $upyun->writeFile('/' . $uploadList[$key]['savepath'], file_get_contents(ROOT . $val['savepath']), true); // 上传图片,自动创建目录 } catch (Exception $e) { // echo $e->getCode().$e->getMessage(); } } } return $uploadList; }
/** * 上传文件 * @access public * @param string $savePath 上传文件保存路径 * @return string * @throws ThinkExecption */ public function upload($savePath = '') { if (!$this->isOpen()) { $this->error = '没有开启云图片功能'; return false; } $fileInfo = array(); $isUpload = false; // 获取上传的文件信息,对$_FILES数组信息处理 $files = $this->dealFiles($_FILES); foreach ($files as $key => $file) { //过滤无效的上传 if (!empty($file['name'])) { $file['key'] = $key; $file['extension'] = $this->getExt($file['name']); if ($this->savePath) { $file['savepath'] = $this->savePath; } else { $file['savepath'] = $this->customPath; } if ($this->saveName) { $file['savename'] = $this->saveName; } else { $file['savename'] = uniqid() . "." . $file['extension']; } //移动设备上传的无后缀的图片,默认为jpg if ($GLOBALS['fromMobile'] == true && empty($file['extension'])) { $file['extension'] = 'jpg'; $file['savename'] = trim($file['savename'], '.') . '.jpg'; } elseif ($this->autoCheck) { if (!$this->check($file)) { return false; } } //计算hash if (function_exists($this->hashType)) { $fun = $this->hashType; $file['hash'] = $fun($file['tmp_name']); } //上传到云服务器 $config = $this->getConfig(); tsload(ADDON_PATH . '/library/upyun.class.php'); $cloud = new UpYun($config['cloud_image_bucket'], $config['cloud_image_admin'], $config['cloud_image_password']); $cloud->setTimeout(60); $file_content = file_get_contents($file['tmp_name']); $res = $cloud->writeFile('/' . $file['savepath'] . $file['savename'], $file_content, true); if (!$res) { $this->error = '上传到云服务器失败!'; return false; } //上传成功后保存文件信息,供其它地方调用 unset($file['tmp_name'], $file['error'], $file_content); $fileInfo[] = $file; $isUpload = true; } } if ($isUpload) { $this->uploadFileInfo = $fileInfo; return true; } else { $this->error = '上传出错!文件不符合上传要求。'; return false; } }
function ftp_get($local_file, $remote_file, $mode, $resumepos = 0) { $upyun = new UpYun($this->upyun_config['bucket_name'], $this->upyun_config['operator_name'], $this->upyun_config['operator_pwd']); $remote_file = discuz_ftp::clear($remote_file); $local_file = discuz_ftp::clear($local_file); try { if ($fh = fopen($local_file, 'wb')) { $rsp = $upyun->readFile($this->upyun_dir . ltrim($remote_file, '/'), $fh); fclose($fh); return $rsp; } else { return 0; } } catch (Exception $e) { return 0; } }
function saveFile($filename, $data, $isAvatar = false, $sync = false) { $upConf = C('upload'); $fileInfo = array('status' => 0, 'width' => 0, 'height' => 0, 'type' => '', 'size' => strlen($data), 'url' => $filename); //临时处理,检查是否由于又拍云导致失败率飙升 if ($isAvatar && !$sync) { $upConf['yun']['open'] = false; } //临时处理,检查是否由于又拍云导致失败率飙升 if ($upConf['yun']['open']) { //开启云存储 T('image/upyun'); try { $upyun = new UpYun($upConf['yun']['bucket'], $upConf['yun']['user'], $upConf['yun']['pwd']); $fileInfo['url'] = $isAvatar ? $filename : $upConf['yun']['dir'] . $filename; $rsp = $upyun->writeFile('/' . $fileInfo['url'], $data, true); // 上传图片,自动创建目录 $fileInfo['status'] = 1; $fileInfo['width'] = $rsp['x-upyun-width']; $fileInfo['height'] = $rsp['x-upyun-height']; $fileInfo['type'] = strtolower($rsp['x-upyun-file-type']); } catch (Exception $e) { // echo $e->getCode().$e->getMessage(); } } else { //本地存储 $filename = $upConf['dir'] . ltrim(str_replace(array('./', '../'), '', $filename), $upConf['dir']); $fileInfo['url'] = $filename; setDir(dirname($filename)); if (file_put_contents(ROOT . $filename, $data)) { $fileInfo['status'] = 1; } } return $fileInfo; }
public function kindedtiropic() { if ($this->upload_type == 'upyun') { $upyun_pic = new UpYun(UNYUN_BUCKET, UNYUN_USERNAME, UNYUN_PASSWORD, $api_access[0]); try { $api_access = array(UpYun::ED_AUTO, UpYun::ED_TELECOM, UpYun::ED_CNC, UpYun::ED_CTT); $domain_pic = 'http://' . UNYUN_DOMAIN; $dir_pic = '/' . $this->token . '/'; $save_path = ''; $save_url = ''; $ext_arr = array('image' => explode(',', C('up_exts')), 'flash' => array('swf', 'flv'), 'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'), 'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2')); $max_size = intval(C('up_size')) * 1000; if (!empty($_FILES['imgFile']['error'])) { switch ($_FILES['imgFile']['error']) { case '1': $error = '超过php.ini允许的大小。'; break; case '2': $error = '超过表单允许的大小。'; break; case '3': $error = '图片只有部分被上传。'; break; case '4': $error = '请选择图片。'; break; case '6': $error = '找不到临时目录。'; break; case '7': $error = '写文件到硬盘出错。'; break; case '8': $error = 'File upload stopped by extension。'; break; case '999': default: $error = '未知错误。'; } $this->alert($error); } if (empty($_FILES) === false) { $file_name = $_FILES['imgFile']['name']; $tmp_name = $_FILES['imgFile']['tmp_name']; $file_size = $_FILES['imgFile']['size']; if (!$file_name) { $this->alert('请选择文件。'); } if (@is_uploaded_file($tmp_name) === false) { $this->alert('上传失败。'); } if ($max_size < $file_size) { $this->alert('上传文件大小超过限制。'); } $dir_name = empty($_GET['dir']) ? 'image' : trim($_GET['dir']); if (empty($ext_arr[$dir_name])) { $this->alert('目录名不正确。'); } $temp_arr = explode('.', $file_name); $file_ext = array_pop($temp_arr); $file_ext = trim($file_ext); $file_ext = strtolower($file_ext); if (in_array($file_ext, $ext_arr[$dir_name]) === false) { $this->alert('上传文件扩展名是不允许的扩展名。' . "\n" . '只允许' . implode(',', $ext_arr[$dir_name]) . '格式。'); } if ($dir_name !== '') { $save_path .= $dir_name . '/'; $save_url .= $dir_name . '/'; } $ymd = date('Ymd'); $save_path .= $ymd . '/'; $save_url .= $ymd . '/'; $new_file_name = date('YmdHis') . '_' . rand(10000, 99999) . '.' . $file_ext; $file_path = $save_path . $new_file_name; $fh = fopen($tmp_name, 'r'); $upyun_pic->writeFile($dir_pic . $file_path, $fh, true); $save_url = $domain_pic . $dir_pic . $save_url; fclose($fh); $file_url = $save_url . $new_file_name; header('Content-type: text/html; charset=UTF-8'); echo json_encode(array('error' => 0, 'url' => $file_url)); exit; } else { $this->alert('您就先别试这里了,我们服务器禁止写入文件了,O(∩_∩)O'); } } catch (Exception $e) { $this->alert($e->getCode() . ':' . $e->getMessage()); } } else { if ($this->upload_type == 'local') { $return = $this->localUpload(); if ($return['error']) { $this->alert($return['msg']); } else { header('Content-type: text/html; charset=UTF-8'); echo json_encode(array('error' => 0, 'url' => $return['msg'])); exit; } } } }
$config = array("savePath" => "upload/", "allowFiles" => array(".rar", ".doc", ".docx", ".zip", ".pdf", ".txt", ".swf", ".wmv"), "maxSize" => 100000); //生成上传实例对象并完成上传 $up = new Uploader("upfile", $config); /** * 得到上传文件所对应的各个参数,数组结构 * array( * "originalName" => "", //原始文件名 * "name" => "", //新文件名 * "url" => "", //返回的地址 * "size" => "", //文件大小 * "type" => "" , //文件类型 * "state" => "" //上传状态,上传成功时必须返回"SUCCESS" * ) */ $info = $up->getFileInfo(); $upyun = new UpYun($file_bucketname, $file_username, $file_password); try { $con = $info["url"]; $opts = array(UpYun::CONTENT_MD5 => md5(file_get_contents($con))); $fh = fopen($con, "rb"); $rsp = $upyun->writeFile("/" . $con, $fh, True, $opts); // 上传图片,自动创建目录 fclose($fh); } catch (Exception $e) { $filename = "error_log.txt"; $errorcontent = "file " . date("Y-m-d H:m:s") . " " . $e->getCode() . " " . $e->getMessage() . "\r\n"; $handle = fopen($filename, 'a'); fwrite($handle, $errorcontent); fclose($handle); exit; }
public function delete() { $id = $_POST['value']; $section = $this->section_model->get_section_by_id($id); if ($section['section_path']) { $path = strstr($section['section_path'], '/img'); $UpYun = new UpYun('code32', 'rxs', 'rxs84217621'); $result = $UpYun->delete($path); } $value = $this->section_model->delete($id); if ($result == 1 && $value == 1) { echo '1'; } else { echo '-1'; } }
public function deleteFile($filepath) { $upyun = new UpYun($this->user['extend']['bucket_name']['value'], SPACEOPERATORS, SPACEOPERATORSPASSWORD); //file_put_contents(CACHE_DIR . 'delete.txt', var_export($this->input,1), FILE_APPEND); try { $result = $upyun->deleteFile($filepath); ///$this->addItem_withkey('error', 0); return true; } catch (Exception $e) { //$this->addItem_withkey('error', '1'); return false; } }
/** * option page * @static * @return void */ public static function plugin_options() { $msg = ''; $error = ''; $upyun = new UpYun(array()); //update options if (isset($_POST['submit'])) { if (self::update_options()) { $msg = __('Options updated.', self::textdomain); } else { $error = __('Nothing changed.', self::textdomain); } $credentials = array('api_domain' => trim($_POST['rest_server']), 'bucketname' => trim($_POST['bucketname']), 'username' => trim($_POST['rest_user']), 'password' => !empty($_POST['rest_pwd']) ? trim($_POST['rest_pwd']) : self::decrypt(self::$rest_pwd), 'form_api_secret' => !empty($_POST['form_api_secret']) ? trim($_POST['form_api_secret']) : self::$form_api_secret, 'timeout' => trim($_POST['rest_timeout']), 'ssl' => FALSE); if (self::connect_remote_server($credentials)) { $msg .= __('Connected and Authenticated successfully.', self::textdomain); } else { $error_arr = self::raise_connection_error(); $error .= $error_arr['error']; } } //tools if (isset($_GET['hacklog_do'])) { global $wpdb; switch ($_GET['hacklog_do']) { case 'replace_old_post_attach_url': $orig_url = self::$local_baseurl; $new_url = self::$remote_baseurl; $sql = "UPDATE {$wpdb->posts} set post_content=replace(post_content,'{$orig_url}','{$new_url}')"; break; case 'recovery_post_attach_url': $orig_url = self::$remote_baseurl; $new_url = self::$local_baseurl; $sql = "UPDATE {$wpdb->posts} set post_content=replace(post_content,'{$orig_url}','{$new_url}')"; break; } if (($num_rows = $wpdb->query($sql)) > 0) { $msg = sprintf('%d ' . __('posts has been updated.', self::textdomain), $num_rows); $msg .= sprintf('%1$s <blockquote><code>%2$s</code></blockquote> ', __('The following SQL statement was executeed:', self::textdomain), $sql); } else { $error = __('no posts been updated.', self::textdomain); } } ?> <div class="wrap"> <?php screen_icon(); ?> <h2> <?php _e('Hacklog Remote Attachment Upyun Options', self::textdomain); ?> </h2> <?php self::show_message($msg, 'm'); self::show_message($error, 'e'); ?> <form name="form1" method="post" action="<?php echo admin_url('options-general.php?page=' . md5(HACKLOG_RA_UPYUN_LOADER)); ?> "> <table width="100%" cellpadding="5" class="form-table"> <tr valign="top"> <th scope="row"><label for="rest_server"><?php _e('REST API server', self::textdomain); ?> :</label></th> <td> <select id="rest_server" name="rest_server"> <?php foreach ($upyun->get_available_api_servers() as $the_server => $server_desc) { ?> <option value="<?php echo $the_server; ?> " <?php selected($the_server, self::get_opt('rest_server'), true); ?> > <?php echo $server_desc; ?> </option> <?php } ?> </select> <span class="description"><?php echo sprintf(__('the IP or domain name of remote file server.', self::textdomain)); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="rest_port"><?php _e('REST API server port', self::textdomain); ?> :</label></th> <td> <input name="rest_port" type="text" class="small-text" size="60" id="rest_port" value="<?php echo self::get_opt('rest_port'); ?> "/> <span class="description"><?php _e('the listenning port of remote rest server.Generally it is 80.', self::textdomain); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="bucketname"><?php _e('bucketname', self::textdomain); ?> :</label></th> <td> <input name="bucketname" type="text" class="regular-text" size="60" id="bucketname" value="<?php echo self::get_opt('bucketname'); ?> "/> <span class="description"><?php _e('the bucketname you want to store your files to.', self::textdomain); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="rest_user"><?php _e('REST API username', self::textdomain); ?> :</label></th> <td> <input name="rest_user" type="text" class="regular-text" size="60" id="rest_user" value="<?php echo self::get_opt('rest_user'); ?> "/> <span class="description"><?php _e('the REST API username.', self::textdomain); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="rest_pwd"><?php _e('REST API password', self::textdomain); ?> :</label></th> <td> <input name="rest_pwd" type="password" class="regular-text" size="60" id="rest_pwd" value=""/> <span class="description"><?php _e('the API user \'s password.will not be displayed here since filled and updated.', self::textdomain); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="form_api_secret"><?php _e('form api secret', self::textdomain); ?> :</label></th> <td> <input name="form_api_secret" type="password" class="regular-text" size="60" id="form_api_secret" value="<?php echo self::get_opt('form_api_secret'); ?> "/> <span class="description"><?php _e('the form API secret.Be aware that if you want to use the <strong>form API features</strong>,you MUST enable this in your Upyun dashboard.', self::textdomain); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="form_api_timeout"><?php _e('form API timeout(s)', self::textdomain); ?> :</label></th> <td> <input name="form_api_timeout" type="text" class="small-text" size="30" id="form_api_timeout" value="<?php echo self::get_opt('form_api_timeout'); ?> "/> <span class="description"><?php _e('form API authorization timeout.the max authorized time (calculated in seconds) when upload file via form API.It depends on your computer\'s network condition.', self::textdomain); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="form_api_content_max_length"><?php _e('form API content max length(MiB)', self::textdomain); ?> :</label></th> <td> <input name="form_api_content_max_length" type="text" class="small-text" size="30" id="form_api_content_max_length" value="<?php echo self::get_opt('form_api_content_max_length'); ?> "/> <span class="description"><?php echo sprintf(__('the max file size (calculated in MiB) when upload file via form API.Currently,Upyun \'s limitation is %d MiB', self::textdomain), UpYun::FORM_API_MAX_CONTENT_LENGTH / 1024 / 1024); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="form_api_allowed_ext"><?php _e('form API allowd ext', self::textdomain); ?> :</label></th> <td> <input name="form_api_allowed_ext" type="text" class="regular-text" size="30" id="form_api_allowed_ext" value="<?php echo self::get_opt('form_api_allowed_ext'); ?> "/> <span class="description"><?php _e('form API allowed file extension.For example: <strong>jpg,jpeg,gif,png,doc,pdf,zip,rar,tar.gz,tar.bz2,7z</strong>', self::textdomain); ?> </span> </td> </tr> <!-- anti-leech --> <tr valign="top"> <th scope="row"><label for="anti_leech_token"><?php _e('anti leech token key', self::textdomain); ?> :</label></th> <td> <input name="anti_leech_token" type="text" class="regular-text" size="60" id="anti_leech_token" value="<?php echo self::get_opt('anti_leech_token'); ?> "/> <span class="description"><?php _e('the anti leech token key your set in upyun panel', self::textdomain); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="anti_leech_timeout"><?php _e('anti leech timeout(s)', self::textdomain); ?> :</label></th> <td> <input name="anti_leech_timeout" type="text" class="small-text" size="30" id="anti_leech_timeout" value="<?php echo self::get_opt('anti_leech_timeout'); ?> "/> <span class="description"><?php _e('anti leech timeout', self::textdomain); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="rest_timeout"><?php _e('rest timeout(s)', self::textdomain); ?> :</label></th> <td> <input name="rest_timeout" type="text" class="small-text" size="30" id="rest_timeout" value="<?php echo self::get_opt('rest_timeout'); ?> "/> <span class="description"><?php _e('rest connection timeout.', self::textdomain); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="remote_baseurl"><?php _e('Remote base URL', self::textdomain); ?> :</label></th> <td> <input name="remote_baseurl" type="text" class="regular-text" size="60" id="remote_baseurl" value="<?php echo self::get_opt('remote_baseurl'); ?> "/> <span class="description"><?php _e('Remote base URL,the URL to your bucket root path.for example: <strong>http://xxx.b0.upaiyun.com</strong>.', self::textdomain); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="rest_remote_path"><?php _e('rest Remote path', self::textdomain); ?> :</label></th> <td> <input name="rest_remote_path" type="text" class="regular-text" size="60" id="rest_remote_path" value="<?php echo self::get_opt('rest_remote_path'); ?> "/> <span class="description"><?php _e('the relative path to your bucket main directory.Use "<strong>.</strong>" for rest main(root) directory.You can use sub-directory Like <strong>wp-files</strong>', self::textdomain); ?> </span> </td> </tr> <tr valign="top"> <th scope="row"><label for="http_remote_path"><?php _e('HTTP Remote path', self::textdomain); ?> :</label></th> <td> <input name="http_remote_path" type="text" class="regular-text" size="60" id="http_remote_path" value="<?php echo self::get_opt('http_remote_path'); ?> "/> <span class="description"><?php _e('the relative path to your HTTP main directory.Use "<strong>.</strong>" for HTTP main(root) directory.You can use sub-directory Like <strong>wp-files</strong>', self::textdomain); ?> </span> </td> </tr> </table> <p class="submit"> <input type="submit" class="button-primary" name="submit" value="<?php _e('Save Options', self::textdomain); ?> »"/> </p> </form> </div> <div class="wrap"> <hr/> <h2> <?php _e('Hacklog Remote Attachment UpYun Status', self::textdomain); ?> </h2> <p style="color:#999999;font-size:14px;"> <?php _e('Space used on remote server:', self::textdomain); ?> <?php if (self::setup_rest()) { $total_size = self::$fs->get_bucket_usage(); if (get_option(self::opt_space) != $total_size) { update_option(self::opt_space, $total_size); } echo self::human_size($total_size); } else { echo '<span style="color:#FF0000;">'; _e('Authentication failed OR Failed to connect to remote server!', self::textdomain); echo '</span>'; } ?> </p> <hr/> <h2>Tools</h2> <p style="color:#f00;font-size:14px;"><strong><?php _e('warning:', self::textdomain); ?> </strong> <?php _e("if you haven't moved all your attachments OR dont't know what below means,please <strong>DO NOT</strong> click the link below!", self::textdomain); ?> </p> <h3><?php _e('Move', self::textdomain); ?> </h3> <p style="color:#4e9a06;font-size:14px;"> <?php _e('if you have moved all your attachments to the remote server,then you can click', self::textdomain); ?> <a onclick="return confirm('<?php _e('Are your sure to do this?Make sure you have backuped your database tables.', self::textdomain); ?> ');" href="<?php echo admin_url('options-general.php?page=' . md5(HACKLOG_RA_UPYUN_LOADER)); ?> &hacklog_do=replace_old_post_attach_url"><strong><?php _e('here', self::textdomain); ?> </strong></a><?php _e(' to update the database.', self::textdomain); ?> </p> <h3><?php _e('Recovery', self::textdomain); ?> </h3> <p style="color:#4e9a06;font-size:14px;"> <?php _e('if you have moved all your attachments from the remote server to local server,then you can click', self::textdomain); ?> <a onclick="return confirm('<?php _e('Are your sure to do this?Make sure you have backuped your database tables.', self::textdomain); ?> ');" href="<?php echo admin_url('options-general.php?page=' . md5(HACKLOG_RA_UPYUN_LOADER)); ?> &hacklog_do=recovery_post_attach_url"><strong><?php _e('here', self::textdomain); ?> </strong></a><?php _e(' to update the database.', self::textdomain); ?> </p> </div> <?php }
function _loadimg($url) { global $db, $proverbkey; $upYun = new UpYun("imgbuket", "tolecen", "11311451167llx"); $fname = md5($url); $file = array(); $oldfile = $db->fetch_first("select * from " . tname("file") . " where SUBSTRING(file_key,12,32)='" . $fname . "'"); if ($oldfile['file_id'] > 0) { return array('id' => $oldfile['file_id'], 'farm' => 'farm1', 'bucket' => 'hbimg', 'key_path' => $oldfile['file_path'], 'key' => $oldfile['file_original'], 'type' => $oldfile['file_type'], 'width' => $oldfile['width'], 'height' => $oldfile['height']); exit; } $f = array('id' => 1, 'farm' => 'farm1', 'bucket' => 'hbimg', 'key_path' => '', 'key' => '', 'type' => 'image/jpeg', 'width' => '180', 'height' => '180'); $r = proverb_getimagesize($url); $imgtype = array('jpg' => '0', 'gif' => '1', 'png' => '2', 'bmp' => '3'); $stuffix = 'jpg'; if (isset($r[0]) && $r[0] > 0) { $c = "abcdefghigklmnopqrstuvwxyz0123456789"; $d = substr($c, rand(0, 20), 2) . '/' . substr($c, rand(0, 10), 2); $dir = ROOT_PATH . '/data/upload'; mkdir2($dir); switch ($r['mime']) { case 'image/gif': $stuffix = 'gif'; break; case 'image/png': $stuffix = 'png'; break; case 'image/bmp': $stuffix = 'bmp'; break; default: $stuffix = 'jpg'; break; } file_put_contents($dir . '/' . $fname . '.' . $stuffix, bidcms_fsockopen($url, $url)); $fileName = $fname . '.' . $stuffix; $filePath = str_replace(ROOT_PATH, "", $dir) . "/"; $filekey = $proverbkey . $imgtype[$stuffix] . $fname . str_replace('/', '', $d); $fh = fopen($dir . "/" . $fileName, 'r'); $upYun->writeFile("/" . $fileName, $fh); fclose($fh); if (is_file($dir . "/" . $fileName)) { @unlink($dir . "/" . $fileName); } $db->query("insert into " . tname("file") . "(`file_key`, `file_path`, `file_original`, `file_type`, `width`, `height`) values('" . $filekey . "','" . $filePath . "','" . $fileName . "','" . $r['mime'] . "','" . $r['0'] . "','" . $r[1] . "')"); $file_id = $db->insert_id(); if ($file_id) { $f = array('id' => $file_id, 'farm' => 'farm1', 'bucket' => 'hbimg', 'key_path' => $filePath, 'key' => $fileName, 'type' => $r['mime'], 'width' => $r[0], 'height' => $r[1]); } } return $f; }
<?php require_once '../upyun.class.php'; $upyun = new UpYun('bucket', 'user', 'pwd'); try { echo "=========获取目录文件列表\r\n"; $list = $upyun->getList('/demo/'); var_dump($list); echo "=========DONE\r\n\r\n"; } catch (Exception $e) { echo $e->getCode(); echo $e->getMessage(); }
<?php require_once '../upyun.class.php'; $upyun = new UpYun('bucket', 'dale', 'dalewu001'); try { echo "=========直接上传文件\r\n"; $fh = fopen('sample.jpeg', 'rb'); $rsp = $upyun->writeFile('/demo/sample_normal.jpeg', $fh, True); // 上传图片,自动创建目录 fclose($fh); var_dump($rsp); echo "=========DONE\n\r\n"; echo "=========设置MD5校验文件完整性\r\n"; $opts = array(UpYun::CONTENT_MD5 => md5(file_get_contents("sample.jpeg"))); $fh = fopen('sample.jpeg', 'rb'); $rsp = $upyun->writeFile('/demo/sample_md5.jpeg', $fh, True, $opts); // 上传图片,自动创建目录 fclose($fh); var_dump($rsp); echo "=========DONE\r\n\r\n"; echo "=========直接生成缩略图,不保存原图片,仅对图片文件有效\r\n"; $opts = array(UpYun::X_GMKERL_TYPE => 'square', UpYun::X_GMKERL_VALUE => 150, UpYun::X_GMKERL_QUALITY => 95, UpYun::X_GMKERL_UNSHARP => True); $fh = fopen('sample.jpeg', 'rb'); $rsp = $upyun->writeFile('/demo/sample_thumb_1.jpeg', $fh, True, $opts); // 上传图片,自动创建目录 fclose($fh); var_dump($rsp); echo "=========DONE\r\n\r\n"; echo "=========按照预先设置的缩略图类型生成缩略图类型生成缩略图,不保存原图,仅对图片空间有效\r\n"; $opts = array(UpYun::X_GMKERL_THUMBNAIL => 'thumbtype'); $fh = fopen('sample.jpeg', 'rb');
<?php @header('Content-Type: text/html; charset=utf-8'); require_once 'upyun.class.php'; require_once '../../../cscms/lib/Cs_Upyun.php'; $uri = $_SERVER["REQUEST_URI"]; $code = explode("down.php", $uri); $path = explode("?size", $code[1]); $upyun = new UpYun(CS_Upy_Bucket, CS_Upy_Name, CS_Upy_Pwd); header('Content-type: application/force-download'); echo $upyun->readFile($path[0]);
} } } if (!$is_gifs) { imagedestroy($new_image); } } else { // 其它文件 // $rsp['msg'] = '本站暂不支持上传非图片附件'; // 涉及安全问题,别开放图片以外的文件上传 // 参见 http://youbbs.sinaapp.com/t-172 // if ($options['upyun_domain'] && $options['upyun_user'] && $options['upyun_pw']) { // 上传到又拍云 include dirname(__FILE__) . '/upyun.class.php'; $upyun = new UpYun($options['upyun_domain'], $options['upyun_user'], $options['upyun_pw']); // 本地调试失败 if ($upyun->writeFile('/' . $upload_filename, $_FILES['filetoupload']['tmp_name'], true)) { $rsp['status'] = 200; $rsp['url'] = '附件:' . $up_name . 'http://' . $options['upyun_domain'] . '.b0.upaiyun.com/' . $upload_filename; $rsp['msg'] = '附件已成功上传'; } else { $rsp['msg'] = '附件保存失败,请稍后再试'; } unset($out_img); } else { // 上传到服务器 if (move_uploaded_file($_FILES['filetoupload']['tmp_name'], $upload_filename)) { $rsp['status'] = 200; $rsp['url'] = '附件:' . $up_name . ' http://' . $_SERVER['HTTP_HOST'] . '/' . $upload_filename; $rsp['msg'] = '文件已成功上传';
static function &get_http_object() { if (is_null(self::$http)) { self::$http = new hacklog_http(); } return self::$http; }
public function deleteYunImg($url = '') { $upConf = C('upload'); T('image/upyun'); try { $upyun = new UpYun($upConf['yun']['bucket'], $upConf['yun']['user'], $upConf['yun']['pwd']); return $upyun->delete('/' . $url); } catch (Exception $e) { // echo $e->getCode().$e->getMessage(); } return false; }
function delete() { $UpYun = new UpYun('code32', 'rxs', 'rxs84217621'); echo $UpYun->delete('/video/875cbbbc8ec551845f0ff360df11376f.mp4'); }
public function sync($offset = 0) { if ($this->wxuser['winxintype'] < 3) { $this->error('没有权限'); } $material = new Material($this->wxuser); $params['post'] = json_encode(array('type' => 'image', 'offset' => $offset, 'count' => '10')); $result = $material->batchget($params); $dirname = '/uploads/' . substr($this->token, 0, 1) . '/' . $this->token . '/material/'; if ('local' == $this->upload_type) { $this->_mkdir('.' . $dirname); } $params['header'] = array('REFERER' => 'http://www.qq.com'); foreach ($result->item as $key => $value) { if (!empty($value->url)) { $file = D('Files')->where(array('sync_url' => $value->url, 'token' => $this->token))->find(); if (empty($file)) { $img = HttpClient::getInstance()->get($value->url, $params); $extension = pathinfo($value->name, PATHINFO_EXTENSION); $filename = $dirname . sha1($value->url) . '.' . $extension; if ('upyun' == $this->upload_type) { $upyun_pic = new UpYun(UNYUN_BUCKET, UNYUN_USERNAME, UNYUN_PASSWORD, $api_access[0]); try { $api_access = array(UpYun::ED_AUTO, UpYun::ED_TELECOM, UpYun::ED_CNC, UpYun::ED_CTT); $domain_pic = 'http://' . UNYUN_DOMAIN; $dir_pic = '/' . $this->token . '/material/' . sha1($value->url) . '.' . $extension; $upyun_pic->writeFile($dir_pic, $img, true); $filename = $domain_pic . $dir_pic; } catch (Exception $e) { echo json_encode(array('error' => 1, 'message' => $e->getCode() . ':' . $e->getMessage())); } } else { $size = file_put_contents('.' . $filename, $img); $filename = $this->siteUrl . $filename; } $Files = new Files(); $Files->index($filename, $size, $extension, $this->user['id'], $this->token, 0, $value->url, $value->media_id); } } } if (($offset + $result->item_count) < $result->total_count) { $this->success('正在同步 ' . $offset . ' - ' . ($offset + $result->item_count) . '张图片,请稍等...不要关闭此窗口', U('Upyun/sync', array('offset' => $offset + $result->item_count))); } else { $this->success('同步完成', U('Img/index')); } }
<?php // header('Content-Type: application/json; charset=utf-8'); require 'vendor/autoload.php'; $config = (require_once './config.php'); require_once './upyun-php-sdk/upyun.class.php'; if (isset($_POST['text'])) { $text = isset($_POST['text']) ? $_POST['text'] : ""; $footer = isset($_POST['footer']) ? $_POST['footer'] : ""; $by = isset($_POST['by']) ? $_POST['by'] : '由scuinfo.com根据热门程度自动生成,并不一定同意此观点! ' . "\n" . '微信关注scuinfo后可直接匿名发布内容到scuinfo.com'; $transform = new Text2pic\Transform($by, './uploads', 'http://docker.dev/uploads'); $result = $transform->generate($text, $footer); if ($result['code'] == 200) { //到这里图片已生成,下面是上传到upyun的代码 $upyun = new UpYun($config['upyun_bucket'], $config['upyun_user'], $config['upyun_password']); try { $opts = array(UpYun::CONTENT_MD5 => md5(file_get_contents($result['data']['path']))); $fh = fopen($result['data']['path'], 'rb'); $fileName = '/uploads/' . md5($result['data']['path']) . '.jpg'; $rsp = $upyun->writeFile($fileName, $fh, True, $opts); // 上传图片,自动创建目录 fclose($fh); unlink($result['data']['path']); //删除服务器的图片 $result = array("code" => 200, "message" => "ok", "data" => array("url" => $config['upyun_base_pic_url'] . $fileName)); echo json_encode($result, JSON_UNESCAPED_UNICODE); } catch (Exception $e) { $result = array("code" => 2003, "message" => $e->getMessage()); echo json_encode($result, JSON_UNESCAPED_UNICODE); } } else {
function kindedtiropic() { if ($this->upload_type == 'upyun') { $upyun_pic = new UpYun(UNYUN_BUCKET, UNYUN_USERNAME, UNYUN_PASSWORD, $api_access[0]); try { $api_access = array(UpYun::ED_AUTO, UpYun::ED_TELECOM, UpYun::ED_CNC, UpYun::ED_CTT); //$php_path = dirname(__FILE__) . '/'; //$php_url = dirname($_SERVER['PHP_SELF']) . '/'; //文件保存目录路径 //$save_path = $php_path . '../attached/'; //文件保存目录URL //$save_url = $php_url . '../attached/'; //$domain_file = $_config['file']['domain']; $domain_pic = 'http://' . UNYUN_DOMAIN; //$dir_file = $_config['file']['dir']; $dir_pic = '/' . $this->token . '/'; $save_path = ''; $save_url = ''; //定义允许上传的文件扩展名 $ext_arr = array('image' => explode(',', C('up_exts')), 'flash' => array('swf', 'flv'), 'media' => array('swf', 'flv', 'mp3', 'wav', 'wma', 'wmv', 'mid', 'avi', 'mpg', 'asf', 'rm', 'rmvb'), 'file' => array('doc', 'docx', 'xls', 'xlsx', 'ppt', 'htm', 'html', 'txt', 'zip', 'rar', 'gz', 'bz2')); //最大文件大小 $max_size = intval(C('up_size')) * 1000; //$save_path = realpath($save_path) . '/'; //PHP上传失败 if (!empty($_FILES['imgFile']['error'])) { switch ($_FILES['imgFile']['error']) { case '1': $error = '超过php.ini允许的大小。'; break; case '2': $error = '超过表单允许的大小。'; break; case '3': $error = '图片只有部分被上传。'; break; case '4': $error = '请选择图片。'; break; case '6': $error = '找不到临时目录。'; break; case '7': $error = '写文件到硬盘出错。'; break; case '8': $error = 'File upload stopped by extension。'; break; case '999': default: $error = '未知错误。'; } $this->alert($error); } //有上传文件时 if (empty($_FILES) === false) { //原文件名 $file_name = $_FILES['imgFile']['name']; //服务器上临时文件名 $tmp_name = $_FILES['imgFile']['tmp_name']; //文件大小 $file_size = $_FILES['imgFile']['size']; //检查文件名 if (!$file_name) { $this->alert("请选择文件。"); } //检查目录 //if (@is_dir($save_path) === false) { // alert("上传目录不存在。"); //} //检查目录写权限 //if (@is_writable($save_path) === false) { // alert("上传目录没有写权限。"); //} //检查是否已上传 if (@is_uploaded_file($tmp_name) === false) { $this->alert("上传失败。"); } //检查文件大小 if ($file_size > $max_size) { $this->alert("上传文件大小超过限制。"); } //检查目录名 $dir_name = empty($_GET['dir']) ? 'image' : trim($_GET['dir']); if (empty($ext_arr[$dir_name])) { $this->alert("目录名不正确。"); } //获得文件扩展名 $temp_arr = explode(".", $file_name); $file_ext = array_pop($temp_arr); $file_ext = trim($file_ext); $file_ext = strtolower($file_ext); //检查扩展名 if (in_array($file_ext, $ext_arr[$dir_name]) === false) { $this->alert("上传文件扩展名是不允许的扩展名。\n只允许" . implode(",", $ext_arr[$dir_name]) . "格式。"); } //创建文件夹 if ($dir_name !== '') { $save_path .= $dir_name . "/"; $save_url .= $dir_name . "/"; //if (!file_exists($save_path)) { // mkdir($save_path); //} } $ymd = date("Ymd"); $save_path .= $ymd . "/"; $save_url .= $ymd . "/"; //if (!file_exists($save_path)) { // mkdir($save_path); //} //新文件名 $new_file_name = date("YmdHis") . '_' . rand(10000, 99999) . '.' . $file_ext; //移动文件 $file_path = $save_path . $new_file_name; $fh = fopen($tmp_name, 'r'); $upyun_pic->writeFile($dir_pic . $file_path, $fh, True); $save_url = $domain_pic . $dir_pic . $save_url; fclose($fh); //if (move_uploaded_file($tmp_name, $file_path) === false) { // alert("上传文件失败。"); //} //@chmod($file_path, 0644); $file_url = $save_url . $new_file_name; header('Content-type: text/html; charset=UTF-8'); echo json_encode(array('error' => 0, 'url' => $file_url)); exit; } else { $this->alert('您就先别试这里了,我们服务器禁止写入文件了,O(∩_∩)O'); } } catch (Exception $e) { $this->alert($e->getCode() . ':' . $e->getMessage()); } } elseif ($this->upload_type == 'local') { $return = $this->localUpload(); if ($return['error']) { $this->alert($return['msg']); } else { header('Content-type: text/html; charset=UTF-8'); echo json_encode(array('error' => 0, 'url' => $return['msg'])); exit; } } }
<?php /** * 设置默认头像,把默认头像 /static/default-avatar.png 上传到又拍云 */ define('IN_SAESPOT', 1); define('ROOT', pathinfo(__FILE__, PATHINFO_DIRNAME)); require ROOT . '/config.php'; require ROOT . '/common.php'; if (!$cur_user || $cur_user['flag'] < 99) { exit('error: 403 Access Denied'); } $tip = ""; if ($options['upyun_avatar_domain'] && $options['upyun_user'] && $options['upyun_pw']) { // 上传到又拍云 $out_img = file_get_contents('./static/default-avatar.png'); include ROOT . '/upyun.class.php'; $upyun = new UpYun($options['upyun_avatar_domain'], $options['upyun_user'], $options['upyun_pw']); if ($upyun->writeFile('/0.jpg', $out_img)) { $tip = '默认头像设置成功'; } else { $tip = '图片保存失败,请稍后再试'; } unset($out_img); } else { $tip = '还没设定头像空间名称和操作用户和密码'; } @header("content-Type: text/html; charset=UTF-8"); echo '<h3>', $tip, '</h3>'; echo '<h4><a href="/">返回首页</a></h4>';
<?php require_once './upyun.class.php'; $upyun = new UpYun('bucketname', 'username', 'password'); $url = "http://xxx.b0.upaiyun.com/2.jpeg\n"; $upyun->purge($url);
$new_w = $img_info[0]; $new_h = $img_info[1]; } $new_image = imagecreatetruecolor($new_w, $new_h); $bg = imagecolorallocate($new_image, 255, 255, 255); imagefill($new_image, 0, 0, $bg); ////目标文件,源文件,目标文件坐标,源文件坐标,目标文件宽高,源宽高 imagecopyresampled($new_image, $img_obj, 0, 0, 0, 0, $new_w, $new_h, $img_info[0], $img_info[1]); imagedestroy($img_obj); // 上传到又拍云 include ROOT . '/upyun.class.php'; ob_start(); imagejpeg($new_image, NULL, 95); $out_img = ob_get_contents(); ob_end_clean(); $upyun = new UpYun($options['upyun_avatar_domain'], $options['upyun_user'], $options['upyun_pw']); // 本地调试失败 if ($upyun->writeFile('/' . $cur_uid . '.jpg', $out_img)) { if ($cur_user['avatar'] != $cur_user['id']) { $DBM = new DB_MySQL(); $DBM->connect($servername_m, $dbport, $dbusername, $dbpassword, $dbname); if ($DBM->unbuffered_query("UPDATE `yunbbs_users` SET `avatar`='{$cur_uid}' WHERE `id`='{$cur_uid}'")) { $cur_user['avatar'] = $cur_user['id']; $MMC->set('u_' . $cur_uid, $cur_user, 0, 600); } else { $tip2 = '数据保存失败,请稍后再试'; } } } else { $tip2 = '图片保存失败,请稍后再试'; }