Sriram Arvind
Sriram Arvind

Reputation: 13

php : file path for windows azure code

I tried to get the file path so that I can upload in windows azure blob container.

  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');
        }
  }

My view:

     <?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 : Error Page This is my code, I use codeigniter. $_FILES is returning array (0) {} when I use var-dump and NULL in print_r.

If I am unable to get the file path, I can't upload the file. So how do I solve it?

Upvotes: 1

Views: 181

Answers (1)

Gary Liu
Gary Liu

Reputation: 13918

As to get the upload files from form, you can to use form_open_multipart() function in the view file.

Please try to modify in your view file:

<?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>

Then in your controller file:

    $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');
        }

Any further concern, please feel free to let me know.

Upvotes: 1

Related Questions