本文整理汇总了PHP中SaeStorage::upload方法的典型用法代码示例。如果您正苦于以下问题:PHP SaeStorage::upload方法的具体用法?PHP SaeStorage::upload怎么用?PHP SaeStorage::upload使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类SaeStorage
的用法示例。
在下文中一共展示了SaeStorage::upload方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: htmlspecialchars
$content = htmlspecialchars($_POST['content']);
$sql = "INSERT INTO lo_share (headline, content, field_id, user_id) VALUES ('" . $headline . "','" . $content . "'," . $field_id . "," . $user_id . ");";
$result = $mysqli->query($sql);
if ($result) {
$images = $_FILES['images']['error'];
$i = 0;
$domin = 'userupload';
$id = $mysqli->insert_id;
$filespath = '';
foreach ($images as $key => $error) {
if ($error == UPLOAD_ERR_OK) {
$filename = "linkedo/" . $user_id . "/" . $id . "/" . time() . $i . ".png";
$tmp_name = $_FILES['images']['tmp_name'][$key];
$s = new SaeStorage();
$filespath = $filespath . $filename . '|';
$s->upload($domin, $filename, $tmp_name);
$i++;
} else {
$jsonArray = array('cid' => '1005', 'ret' => '1', 'image_error' => $i);
echo json_encode($jsonArray);
}
}
$sql = "update lo_share set images = '" . $filespath . "' where id=" . $id;
$result = $mysqli->query($sql);
if ($result) {
$jsonArray = array('cid' => '1005', 'ret' => '1');
echo json_encode($jsonArray);
} else {
$jsonArray = array('cid' => '1005', 'ret' => '0');
echo json_encode($jsonArray);
}
示例2: upFile
/**
* 上传文件的主处理方法
* @param $base64
* @return mixed
*/
private function upFile($base64)
{
//处理base64上传
if ("base64" == $base64) {
$content = $_POST[$this->fileField];
$this->base64ToImage($content);
return;
}
//处理普通上传
$file = $this->file = $_FILES[$this->fileField];
if (!$file) {
$this->stateInfo = $this->getStateInfo('POST');
return;
}
if ($this->file['error']) {
$this->stateInfo = $this->getStateInfo($file['error']);
return;
}
if (!is_uploaded_file($file['tmp_name'])) {
$this->stateInfo = $this->getStateInfo("UNKNOWN");
return;
}
$this->oriName = $file['name'];
$this->fileSize = $file['size'];
$this->fileType = $this->getFileExt();
if (!$this->checkSize()) {
$this->stateInfo = $this->getStateInfo("SIZE");
return;
}
if (!$this->checkType()) {
$this->stateInfo = $this->getStateInfo("TYPE");
return;
}
/*$this->fullName = $this->getFolder() . '/' . $this->getName();
if ( $this->stateInfo == $this->stateMap[ 0 ] ) {
if ( !move_uploaded_file( $file[ "tmp_name" ] , $this->fullName ) ) {
$this->stateInfo = $this->getStateInfo( "MOVE" );
}
}*/
$this->fullName = $this->getFolder() . '/' . $this->getName();
if ($this->stateInfo == $this->stateMap[0]) {
if (!defined('SAE_TMP_PATH')) {
if (!move_uploaded_file($file["tmp_name"], $this->fullName)) {
$this->stateInfo = $this->getStateInfo("MOVE");
}
} else {
$st = new SaeStorage();
$url = $st->upload('upload', $this->fullName, $file["tmp_name"]);
if (!$url) {
$this->stateInfo = $this->getStateInfo("MOVE");
} else {
$this->fullName = $url;
}
}
}
}
示例3: md5
<?php
session_start();
include_once 'saestorage.class.php';
?>
<html>
<body>
<form action="index.php" method="post" enctype="multipart/form-data">
<input type = "file" name="myfile" size="100" /><br>
<input type = "submit" value= "upload" / >
</form>
</body>
</html>
<?php
$domain = "itemsimage";
$file_name = $_FILES["myfile"]["name"];
$temp_arr = explode(".", $file_name);
$file_ext = array_pop($temp_arr);
$file_ext = trim($file_ext);
$file_ext = strtolower($file_ext);
$new_file_name = date("YmdHis") . '_' . rand(10000, 99999) . '.' . $file_ext;
$s = new SaeStorage();
//$s->upload( 'imagefile',$_FILES["myfile"]["name"],$_FILES["myfile"]["name"]);
echo $aimage = $s->upload('itemsimage', $new_file_name, $_FILES["myfile"]["tmp_name"]);
echo md5("123456");
示例4: SaeStorage
/**
* 用flash添加照片
*/
function add_photo()
{
if ($_FILES) {
global $php;
$php->upload->thumb_width = 136;
$php->upload->thumb_height = 136;
$php->upload->max_width = 500;
$php->upload->max_height = 500;
$php->upload->thumb_qulitity = 100;
if (class_exists('SaeStorage', false)) {
$s = new SaeStorage();
$file_id = uniqid('pic_', false) . mt_rand(1, 100);
$tmp_file = SAE_TMP_PATH . '/thum_' . $file_id . '.jpg';
Image::thumbnail($_FILES['Filedata']['tmp_name'], $tmp_file, $php->upload->thumb_width, $php->upload->thumb_height, $php->upload->thumb_qulitity, false);
$pic = '/uploads/' . $file_id . ".jpg";
$ret = $s->upload('static', $pic, $_FILES['Filedata']['tmp_name']);
if ($ret) {
$data['picture'] = $s->getUrl('static', $pic);
} else {
echo $s->errmsg() . ' : ' . $s->errno();
return;
}
$thum_pic = '/uploads/thum_' . $file_id . '.jpg';
$ret = $s->upload('static', $thum_pic, $tmp_file);
if ($ret) {
$data['imagep'] = $s->getUrl('static', $thum_pic);
} else {
echo $s->errmsg() . ' : ' . $s->errno();
return;
}
} else {
$php->upload->sub_dir = 'user_images';
$up_pic = Swoole::$php->upload->save('Filedata');
if (empty($up_pic)) {
return '上传失败,请重新上传! Error:' . $php->upload->error_msg;
}
$data['picture'] = $up_pic['name'];
$data['imagep'] = $up_pic['thumb'];
}
$data['uid'] = $_POST['uid'];
$up_pic['photo_id'] = $this->swoole->model->UserPhoto->put($data);
/* if(isset($_POST['post']))
{
Api::feed('photo', $data['uid'], 0, $up_pic['photo_id']);
} */
return json_encode($up_pic);
} else {
$this->swoole->tpl->display('myphoto_add_photo.html');
}
}
示例5: upradio
static function upradio($radio)
{
$s = new SaeStorage();
$mname = $_FILES[$radio]['name'];
$msize = $_FILES[$radio]['size'];
if ($mname != "") {
if ($msize > 10240000) {
echo '图片大小不能超过10M';
exit;
}
$type = strstr($mname, '.');
if ($type != ".mp3") {
echo '对不起!只支持mp3格式,如果是这几种格式请去掉处文件标识符以外的点"."';
exit;
}
if (!$_FILES[$radio]['name']) {
die('没有选择文件!');
}
//上传文件校验,可以添加文件类型等检验、此处简略处理
$file_name = "m_" . time() . rand(100, 999);
//定义保存的文件名称
$m_path = $file_name . $type;
//要保存的文件路径+文件名,此处保存在根目录下
$link = $s->upload('upcon', $m_path, $_FILES[$radio]['tmp_name']);
if ($link) {
$out_radio = array('m_name' => $file_name, 'm_url' => $link);
echo json_encode($out_radio);
} else {
$emsg = $s->errmsg();
$this->writelog_debug($emsg);
die('上传零时文件失败!');
}
}
}
示例6: submit
function submit()
{
//var_dump($_FILES);exit;
if (!$this->has_privilege()) {
$this->json->output(array('success' => false, 'm' => '您没有使用该功能的权限'));
}
$proj_id = $this->input->post('proj_id');
if (!$this->utility->chk_id($proj_id)) {
$this->json->output(array('success' => false, 'm' => '输入的记录编号错误'));
}
$max_size = 10;
// filesize MB
if ($_FILES['file']['size'] > $max_size * 1024 * 1024) {
$this->json->output(array('success' => false, 'm' => '上传文件大小不能超过' . $max_size . 'MB'));
}
if (!empty($_FILES)) {
$s = new SaeStorage(SAE_ACCESSKEY, SAE_SECRETKEY);
$url = $s->upload('upload', $_FILES['file']['name'], $_FILES['file']['tmp_name']);
if (!$url) {
$this->json->output(array('success' => false, 'm' => $s->errmsg()));
}
// insert into upload table
$id = $this->Proj_model->create_upload($proj_id, $_FILES['file']['name'], $_FILES['file']['size']);
// extjs json decode bug, using echo instead of output
// $this->json->output(array('success' => true, 'url' => $url));
echo '{"success":true, "file":"' . $_FILES['file']['name'] . '"}';
exit;
}
}
示例7: saeup
function saeup($date, $filename)
{
$storage = new SaeStorage();
$domain = 'img';
$destFileName = $filename . 'jpg';
$srcFileName = $_FILES['tmp_name'];
$result = $storage->upload($domain, $destFileName, $date["tmp_name"]);
return $result;
}
示例8: Storage
/**
* @param $tmp
* @param $upload
*/
function Storage($tmp, &$upload)
{
global $zbp, $domainname;
$filename = date("Ymd", time()) . mt_rand(1000, 9999) . '_' . mt_rand(0, 1000) . '.' . GetFileExt($upload->SourceName);
$object = date("Y/m/", time()) . $filename;
//构造云文件名
$upload->Name = $filename;
$s = new SaeStorage();
$url = $s->upload($domainname, $object, $tmp);
$upload->Metas->Storage_URL = $object;
$GLOBALS['Filter_Plugin_Upload_SaveFile']['Storage'] = PLUGIN_EXITSIGNAL_RETURN;
}
示例9: upload_mp3
function upload_mp3($filePath, $fileName)
{
$stor = new SaeStorage();
$stor->upload(SAE_DOMAIN, $fileName, $filePath);
$errmsg = $stor->errmsg();
//var_export($errmsg);
if ($errmsg == 0) {
$result['success'] = 1;
$result['url'] = $stor->getUrl(SAE_DOMAIN, $fileName);
} else {
$result['success'] = -1;
}
return $result;
}
示例10: SaeStorageUpload
function SaeStorageUpload($FilePath, $srcFileName)
{
$storage = new SaeStorage();
$domain = Sae_Storage_Domain_Name;
//domain名称
//$srcFileName = $_FILE['tmp_name'];//参数类似这样
$size = -1;
//长度限制
//$attr = array('encoding'=>'gzip');//文件属性(gzip压缩)
//$compress = true;//文件是否gzip压缩
$attr = array();
$compress = false;
$result = $storage->upload($domain, $FilePath, $srcFileName, $size, $attr, $compress);
return $result;
}
示例11: upFile
private function upFile($base64)
{
if ("base64" == $base64) {
$content = $_POST[$this->fileField];
$this->base64ToImage($content);
return null;
}
$file = $this->file = $_FILES[$this->fileField];
if (!$file) {
$this->stateInfo = $this->getStateInfo("POST");
return null;
}
if ($this->file["error"]) {
$this->stateInfo = $this->getStateInfo($file["error"]);
return null;
}
if (!is_uploaded_file($file["tmp_name"])) {
$this->stateInfo = $this->getStateInfo("UNKNOWN");
return null;
}
$this->oriName = $file["name"];
$this->fileSize = $file["size"];
$this->fileType = $this->getFileExt();
if (!$this->checkSize()) {
$this->stateInfo = $this->getStateInfo("SIZE");
return null;
}
if (!$this->checkType()) {
$this->stateInfo = $this->getStateInfo("TYPE");
return null;
}
$this->fullName = $this->getFolder() . "/" . $this->getName();
if ($this->stateInfo == $this->stateMap[0]) {
if (!defined("SAE_TMP_PATH")) {
if (!move_uploaded_file($file["tmp_name"], $this->fullName)) {
$this->stateInfo = $this->getStateInfo("MOVE");
}
} else {
$st = new SaeStorage();
$url = $st->upload("data", $this->fullName, $file["tmp_name"]);
if (!$url) {
$this->stateInfo = $this->getStateInfo("MOVE");
} else {
$this->fullName = $url;
}
}
}
}
示例12: save
/**
* 保存指定文件
* @param array $file 保存的文件信息
* @param boolean $replace 同名文件是否覆盖
* @return boolean 保存状态,true-成功,false-失败
*/
public function save($file, $replace = true)
{
$filename = ltrim($this->rootPath . '/' . $file['savepath'] . $file['savename'], '/');
$st = new \SaeStorage();
/* 不覆盖同名文件 */
if (!$replace && $st->fileExists($this->domain, $filename)) {
$this->error = '存在同名文件' . $file['savename'];
return false;
}
/* 移动文件 */
if (!$st->upload($this->domain, $filename, $file['tmp_name'])) {
$this->error = '文件上传保存错误![' . $st->errno() . ']:' . $st->errmsg();
return false;
}
return true;
}
示例13: save
/**
* 保存上传文件
*
* 需要设置存放SAE的domain,可修改 Upload::$default_directory = 'newdomain';
*
* @param array $file
* @param string $filename
* @param string $directory
* @param int $chmod
*/
public static function save(array $file, $filename = NULL, $directory = NULL, $chmod = 0644)
{
if (!isset($file['tmp_name']) or !is_uploaded_file($file['tmp_name'])) {
// Ignore corrupted uploads
return false;
}
if ($filename === null) {
// Use the default filename, with a timestamp pre-pended
$filename = uniqid() . $file['name'];
}
if (Upload::$remove_spaces === true) {
// Remove spaces from the filename
$filename = preg_replace('/\\s+/', '_', $filename);
}
$obj = new SaeStorage();
return $obj->upload(Upload::$default_directory, $filename, $file['tmp_name']);
}
示例14: handleFiles
function handleFiles($typeId, $tmpNames, $names)
{
global $IS_SAE;
$result = array("success" => true, "details" => array());
$ext_arr = array();
for ($i = 0; $i < count($names); $i++) {
$tmp = explode(".", $names[$i]);
$tmp = $tmp[count($tmp) - 1];
array_push($ext_arr, $tmp);
}
// when name the folder, here we wipe the parameter $type.
$directory = "../resources/chart/{$typeId}/";
if ($IS_SAE) {
$st = new SaeStorage();
$attr = array('encoding' => 'gzip');
for ($i = 0; $i < count($names); $i++) {
$tName = $tmpNames[$i];
$oName = $names[$i];
$file_new_name = date("YmdHis") . str_pad(rand(0, 9999), 4, rand(0, 9), STR_PAD_LEFT) . "." . $ext_arr[$i];
$uploadRes = $st->upload($_SERVER['HTTP_APPNAME'], $file_new_name, $_FILES['photo']['tmp_name'][$i], $attr, true);
if ($uploadRes === false) {
array_push($result["details"], array("success" => false, "msg" => "图片'{$oName}'上传失败!error:" . $st->errno() . ' ' . $st->errmsg(), "file" => '', "original_file_name" => $oName));
} else {
array_push($result["details"], array("success" => true, "msg" => "图片'{$oName}'上传成功!重命名为'{$file_new_name}'。", "file" => $uploadRes, "original_file_name" => $oName));
}
}
} else {
if (!file_exists($directory)) {
if (!mkdir($directory)) {
throw new Exception("文件夹创建失败!" . $directory);
}
}
for ($i = 0; $i < count($names); $i++) {
$tName = $tmpNames[$i];
$oName = $names[$i];
$file_new_name = date("YmdHis") . str_pad(rand(0, 9999), 4, rand(0, 9), STR_PAD_LEFT) . "." . $ext_arr[$i];
if (move_uploaded_file($tName, $directory . $file_new_name)) {
array_push($result["details"], array("success" => true, "msg" => "图片'{$oName}'上传成功!重命名为'{$file_new_name}'。", "file" => $directory . $file_new_name, "original_file_name" => $oName));
} else {
array_push($result["details"], array("success" => false, "msg" => "图片'{$oName}'上传失败!", "file" => '', "original_file_name" => $oName));
}
}
}
return $result;
}
示例15: Save
public function Save($file, $fileType)
{
$res = $this->Validate($file, $fileType);
if ($res['result']) {
$file_name = md5($file['name'] . uniqid()) . $res['reason'];
//sae upload
$s = new SaeStorage();
$save_path = SAE_MODULES . '/' . $file_name;
$save = $s->upload(SAE_STORAGE_DOMAIN, $save_path, $file["tmp_name"]);
if ($save !== false) {
$res['reason'] = $file_name;
} else {
$res['result'] = false;
$res['reason'] = $this->messages['3'];
}
}
return $res;
}