上傳和下載圖像我試圖從使用Azure的PHP SDK中的HTML表單Azure的Blob存儲上傳圖片。當我嘗試下載圖像時出現問題。結果頁面可以在帖子的底部看到。在Azure的Blob存儲
我存儲使用臨時名稱的圖像,我覺得這是兩個問題之一。我不確定,但第二個問題是下載圖像時。我必須將它從getContentStream()轉換爲圖像嗎?
$ _FILES [ 'driverLicenseFront'] [ 'tmp_name的值']
這是HTML形式上傳的圖片:
<form role="form" method="POST" action="{path_to_controller}" data-toggle="validator" enctype="multipart/form-data">
<div class="form-group">
<label for="driverLicenseFront">Upload Driver's License(Front)</label>
<input type="file" id="driverLicenseFront" name="driverLicenseFront">
</div>
<submit button>
</form>
在我的文件存儲這樣的控制器:
// First check if there is a container
$blob = New Blob($_SESSION['userid']);
$blob->createContainerIfNotExists();
// Upload image to Azure Blob Storage
$content = fopen($_FILES['driverLicenseFront']['tmp_name'].'', "r");
$blob->uploadToContainer($content,'DriverLicenseFrontSide');
斑點是我的自定義類來處理斑點
我需要使用鏈接下載文件:
<a href="../controller/blobs.php?blob_name=DriverLicenseFrontSide" target="_new">Download</a>
我捕捉到控制器的要求:
if(isset($_GET['blob_name'])){
$blob = New Blob($_SESSION['userid']);
$blob->downloadBlob($_GET['blob_name']);
}
功能Blob類別:
public function downloadBlob($blob_name){
try {
// Get blob.
$blob = $this->blobRestProxy->getBlob($this->containerName, $blob_name.'.jpg');
fpassthru($blob->getContentStream());
}
catch(ServiceException $e){
// Handle exception based on error codes and messages.
// Error codes and messages are here:
// http://msdn.microsoft.com/library/azure/dd179439.aspx
$code = $e->getCode();
$error_message = $e->getMessage();
echo $code.": ".$error_message."<br />";
}
}
結果:
JFIF ,, ICC_PROFILEmntrRGB XYZ $ ACSP - )=ޯUxBʃ9descDybXYZbTRCdmdd gXYZ hgTRC lumi| meas $ bkpt rXYZ rTRC tech已更新 wtptpcprt 7chad ,descsRGB IEC61966-2-1 black scaledXYZ $ curv#( - 27; @ EJOTY^chmrw | ...
嗨Mitsos,必須立即解決您的問題? –