【发布时间】:2016-03-11 18:03:46
【问题描述】:
我有问题,我的 orig_name 文件上传成功上传到数据库但文件没有上传到我的文件夹中..
这是我的控制器代码
public function insert(){
$this->model->register();
$this->run_upload();
redirect('Controling/daftar');
}
public function run_upload(){
$config['upload_path'] = './upload/';
$config['allowed_types'] = 'gif|jpg|png|pdf';
$config['max_size'] = '100000';
$config['max_width'] = '3024';
$config['max_heigth'] = '2024';
$this->load->library('upload', $config);
$data = array('upload_data' => $this->upload->data());
$datafoto=$this->upload->data();
$nm_file = time().$datafoto['orig_name'];
$this->load->model('model');
$this->model->update_file($nm_file);
copy('upload/'.$datafoto['orig_name'], 'upload/'.$nm_file);
}
这是我的视图代码
<?php echo form_open_multipart('Controling/insert', 'form="form"')?>
<h2 class="">Register</h2>
<label>Nim</label><input type="text" name="nim" class="form-control"><br />
<label>Username</label><input type="text" name="username" class="form-control"><br />
<label>Password</label><input type="password" name="password" class="form-control"><br />
<label>Masukkan File</label>
<input type="file" name="userfile" size="20" class="form-control"><br />
<input class="btn btn-primary" type="submit" name="register" value="Daftar">
<?php echo form_close(); ?>
【问题讨论】:
-
把
$config['upload_path'] = './upload/';改成$config['upload_path'] = '../upload/';看看。 -
它不工作娜娜
-
用于将文件移动到文件夹。你在用这条线
copy('upload/'.$datafoto['orig_name'], 'upload/'.$nm_file);吗? -
是的,我认为这行得通,为什么?
-
试试这个 $config['upload_path'] = str_replace("\\","/",FCPATH).'upload/';并设置777上传文件夹
标签: php file codeigniter file-upload