php:windows azure代码的文件路径

时间:2016-06-19 18:51:59

标签: php windows codeigniter azure

我试图获取文件路径,以便我可以在windows azure blob容器中上传。

  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。当我在print_r中使用var-dump和NULL时,$ _FILES返回array(0){}。

如果我无法获取文件路径,则无法上传文件。那么我该如何解决呢?

1 个答案:

答案 0 :(得分:1)

为了从表单获取上传文件,您可以在视图文件中使用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');
        }

如有任何疑问,请随时告诉我。