我试图获取文件路径,这样我就可以在容器中上传。
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>错误:错误页,这是我的代码,我使用代码点火器。当我在$_FILES中使用var-dump和NULL时,print_r返回数组(0) {}。
如果无法获得文件路径,则无法上载该文件。那我该怎么解决呢?
发布于 2016-06-20 05:13:23
要从表单中获取上传文件,可以在视图文件中使用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');
}如有任何进一步的关注,请随时通知我。
https://stackoverflow.com/questions/37910682
复制相似问题