【发布时间】:2014-01-14 12:15:00
【问题描述】:
我有这个在 windows azure storage 中上传图片的 php 源
<?php
require_once('WindowsAzure/WindowsAzure.php');
use WindowsAzure\Common\ServicesBuilder;
use WindowsAzure\Common\ServiceException;
// Create blob REST proxy.
$connectionString='DefaultEndpointsProtocol=http;AccountName=myaccount;AccountKey=jNbf/qmRENb1HZpSqE/SnkAi8WQyUKPE7AaFgVu1u0AFGPEUsbWW10Y+fZud1OOn7zi18J5VnSC0NadZXU8Bpvsg==';
$blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString);
$path="files/";
foreach ($_FILES as $key) {
if($key['error'] == UPLOAD_ERR_OK ){
$name = $key['name'];
$temp = $key['tmp_name'];
$size= ($key['size'] / 1000)."Kb";
move_uploaded_file($temp, $path. $name);
$content = fopen($path.$name, "r");
$blob_name = $name;
try {
$blobRestProxy->createBlockBlob("imgs", $blob_name, $content);
}
catch(ServiceException $e){
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
echo "
<div id='loaded'>
<h12><strong>File Name: $nombre</strong></h2><br />
<h12><strong>Size: $tamano</strong></h2><br />
<hr>
</div>
";
}else{
echo $key['error'];
}
}
?>
问题是我必须先将文件保存在服务器硬盘中,然后将其发送到windows azure中的容器,可以跳过这一步直接发送到windows azure,避免这一行 move_uploaded_file($temp, $path.$name);?,因为我试过这样做:
$content = $key['tmp_name'];但是不行
【问题讨论】:
标签: php windows file azure upload