我有一個可以上載多個文件的表單。上傳一次的文件上傳到一個唯一的目錄中。我現在面臨的問題是,對於一個用戶,我想運行一次mkdir()
。不知道如何去做。在控制器的方法中調用mkdir()一次
Controller.php這樣
class Upload_file extends CI_Controller
{
function __construct()
{
parent::__construct();
$this->load->helper(array('form', 'url'));
}
function upload_it()
{
$this->load->helper('form');
$uniqueID = uniqid();
mkdir("application/uploads/".$uniqueID);
$config['upload_path'] = 'application/uploads/'.$uniqueID;
$config['allowed_types'] = '*';
$this->load->library('upload', $config);
$this->upload->initialize($config);
$this->upload->set_allowed_types('*');
$data['upload_data'] = '';
if (!$this->upload->do_multi_upload('files')) {
$data = array('msg' => $this->upload->display_errors());
}
else
{
$data['upload_data'] = $this->upload->get_multi_upload_data();
}
$this->load->vars($data);
$this->load->view('upload');
}
}
HTML
<form target="upload_target" id="fileupload" method="post" action="<?php echo site_url('upload_file/upload_it'); ?>" enctype="multipart/form-data">
<div class="fileUpload btn btn-warning">
<span>Browse</span>
<input id="uploadBtn" type="file" multiple="multiple" name="files[]" class="upload" />
</div>
<input id="uploadFile" style="width: 160px; margin-top: 30px;float: left;height: 35px;" placeholder="Choose File" disabled="disabled" />
<button id="btnupload" style="padding: 4.5px; float:left;margin-top: 30px;border-radius: 0px;" disabled="disabled" type="submit" class="btn btn-primary btn-lg"><span class="glyphicon glyphicon-upload"></span></button>
</form>
它的一個很好的做法是在創建之前檢查文件夾是否已經存在。 –
不明白你的問題。它看起來確定你寫在那裏?! – Xatenev