2016-06-19 31 views
0

我试图获取文件路径,以便我可以在Windows azure blob容器中上传。php:Windows Azure代码的文件路径

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 这是我的代码,我用笨。 $ _FILES返回数组(0){}当我使用var-dump和NULL在print_r。

如果我无法获取文件路径,我不能上传文件。那么我如何解决它?

+0

你在哪里打开你的 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

感谢像魅力一样工作。 –