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.";
    }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥20 求各位懂行的人,注册表能不能看到usb使用得具体信息,干了什么,传输了什么数据
  • ¥15 个人网站被恶意大量访问,怎么办
  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 Centos / PETGEM
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制