douluokuang7184 2012-01-06 14:03
浏览 20
已采纳

AzurePHP:通过对话上传到Blob?

I'm new to PHP so this is probably a super trivial task:

Right now I'm uploading files to a blob from within the script without allowing the user to select a particular file:

$result = $storageClient->putBlob('testcontainer', 'example.txt', 'C:/example.txt');
// Syntax: putBlob (ContainerName, NameInStorage, FileLocation)

I'd like to offer the user three input boxes so that he/she can upload three files to the blob in one go. Something like this:

//GetFile1Location();
//GetFile2Location();
//GetFile3Location();


$result = $storageClient->putBlob('testcontainer', 'example.txt', 'File1Location');
$result = $storageClient->putBlob('testcontainer', 'example.txt', 'File2Location');
$result = $storageClient->putBlob('testcontainer', 'example.txt', 'File3Location');
// Syntax: putBlob (ContainerName, NameInStorage, FileLocation)

I've looked at the w3schools tutorial for file uploading but I think all I need is a means to select a file and pull its path; putBlob seems to take care of the actual uploading. I'm just having a bit of trouble with the "GetFileLocation" action.

Any tips would be much appreciated.

  • 写回答

1条回答 默认 最新

  • duanlei2150 2012-01-06 15:01
    关注

    I may be dating myself (and my php skills here), but it should just be a matter of doing the file selection/upload as you would normally. Then you just stream the file from its temporary location into the blob container via the code you have already laid out. You can find an example of doing the file upload at http://www.tizag.com/phpT/fileupload.php

    I'll work up a code sample for you over the weekend (simply don't have time today).

    Jan 20th Update Sorry it took so long, but here's the promised code sample.

    require_once('Microsoft/AutoLoader.php');
    
    if (!empty($_FILES['userfile']['name']))
    {
        $container = 'sampleblobs';
        $filename = "somefolder/".$_FILES['userfile']['name'];
    
        $blobStorageClient = new Microsoft_WindowsAzure_Storage_Blob();
        $blobStorageClient->createContainerIfNotExists($container);
    
        $blobStorageClient->putBlob(
            $container, // container name
            $filename,  // name in storage
            $_FILES['userfile']['tmp_name'],  // object to upload
            array('createdby' => 'CodeMash', 'FileType' => 'jpg') // metadata
        );
    
        echo "<br>file uploaded.";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥500 火焰左右视图、视差(基于双目相机)
  • ¥100 set_link_state
  • ¥15 虚幻5 UE美术毛发渲染
  • ¥15 CVRP 图论 物流运输优化
  • ¥15 Tableau online 嵌入ppt失败
  • ¥100 支付宝网页转账系统不识别账号
  • ¥15 基于单片机的靶位控制系统
  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本