2016-06-19 4 views
0

私はWindows Azure blob containerにアップロードできるようにファイルパスを取得しようとしています。php:Windows Azure Codeのファイルパス

public function upload_container() 
    { 

     $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString); 
     $this -> load -> helper('form'); 
     $this -> load -> helper('url'); 
     $result=$this-> input ->post('file'); 
     $result1=$_FILES['file']['tmp_name']; 

     if($result != NULL) 
     { 
      $content = fopen($result1, "r");; 
      $blob_name = "myblob3.jpg"; 

      try { 
       $blobRestProxy->createBlockBlob("mycontainer", $blob_name, $content); 
       $data['blob_error']="check Azure Container"; 
       $this->load->view('blob',$data); 
      } 
      catch(ServiceException $e){ 
       $code = $e->getCode(); 
       $error_message = $e->getMessage(); 
       echo $code.": ".$error_message."<br />"; 
      } 
     }else{ 
      $this -> load -> helper('form'); 
      $this-> load -> view('blob'); 
     } 
    } 

私の見解

 <?php 
echo form_open('blob/upload_container'); 
?> 
Select a file: 
<input type="file" name="file" id="file"> 
<input type="submit" value="Upload Image" name="submit"> 

<?php if(isset($blob_error)){echo $blob_error;} ?> 


</form> 

エラー: Error Page これは私のコードですが、私はCodeIgniterのを使用しています。 $ _FILESはarray_(0){}を返します。これは、print-rでvar-dumpとNULLを使用するときです。

ファイルのパスを取得できない場合は、ファイルをアップロードできません。だから私はそれをどのように解決するのですか?

+0

ここでur jmattheis

+0

echo form_open( 'blob/upload_container'); - >フォームのタグを開く –

答えて

0

フォームからアップロードファイルを取得するには、ビューファイルでform_open_multipart()関数を使用できます。

ビューファイルに変更してみてください:

<?php 
echo form_open_multipart('text/upload_container'); 
?> 
Select a file: 
<input type="file" name="file" id="file"> 
<input type="submit" value="Upload Image" name="submit"> 
<?php if (isset($blob_error)) {echo $blob_error;}?> 
</form> 

その後、あなたのコントローラファイルで:

$connectionString = "<connectionString>"; 
     $blobRestProxy = ServicesBuilder::getInstance()->createBlobService($connectionString); 
     $this -> load -> helper('form'); 
     $this -> load -> helper('url'); 
     $result1=$_FILES['file']['tmp_name']; 
     if($result1 != NULL) 
     { 
      $content = fopen($result1, "r"); 
      $blob_name = "myblob3.jpg"; 
      try { 
       $blobRestProxy->createBlockBlob("mycontainer", $blob_name, $content); 
       $data['blob_error']="check Azure Container"; 
       $this->load->view('blob',$data); 
      } 
      catch(ServiceException $e){ 
       $code = $e->getCode(); 
       $error_message = $e->getMessage(); 
       echo $code.": ".$error_message."<br />"; 
      } 
     }else{ 
      $this -> load -> helper('form'); 
      $this-> load -> view('blob'); 
     } 

どれ更なる懸念、私に知らせて自由に感じなさい。

+0

感謝のように働いてくれてありがとう。 –

関連する問題