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

报告相同问题?