上传的文件未保存在文件夹中

时间:2014-08-20 09:41:30

标签: php codeigniter file-upload

我已经尝试了一切,但我仍然无法弄清楚为什么上传的文件没有保存在任何地方..... 我的HTML代码:

<form enctype='multipart/form-data' action='generate_xml.php' method='POST'>
<table>
<tr>
<td>Enter Remote ID :</td> <td> <input type='text' name='remote' required /></td><br />       </tr><tr>
<td>Enter Alter_id :    </td><td> <input type='text' name='alter' required/></td> <br />     </tr><tr>
<td>Enter Master ID :    </td><td><input type='text' name='master' required/> </td><br /></tr><tr>
<td>Enter Vch ID :      </td><td> <input type='text' name='vch' required/> </td><br /></tr><tr>
<td>Enter Date Account : </td><td><input type='text' name='date' required/> </td><br /></tr><tr>
<td>Choose a file to upload: <input name='uploadedfile' type='file' /></td><br /></tr>

<tr><td>
<input type='submit' value='submit' /></td>
</tr>
</table>
</form>

这是我的代码

if(! empty($_FILES['uploadedfile']['name']))
    {
        $this->config->load('je_settings',TRUE);
        $tally_folder_path = $this->config->item('tally_folder_path');
        $template_file_path = FCPATH;
        $tally_folder_path="/home/torrez/Public/";
        $file_type = $_FILES['uploadedfile']['type'];
        $allowed = array('text/csv','text/comma-separated-values');
        if( ! empty($_FILES['uploadedfile']['name']) && in_array($file_type, $allowed))
        {
            $tally_src_file = $tally_folder_path . basename( $_FILES['uploadedfile']      ['name']);
            $name = basename( $_FILES['file']['name']);
            move_uploaded_file($name, $tally_folder_path);
        }
        else
        {
            die("No file specified or Format not supported");
        }

请帮助!!!

4 个答案:

答案 0 :(得分:2)

将名称更改为tmp_name$_FILES['uploadedfile']

$name = $_FILES['uploadedfile']['tmp_name'];

答案 1 :(得分:2)

包含src文件路径而不是文件文件路径....

$tally_src_file = $tally_folder_path . basename( $_FILES['uploadedfile']['name']);
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $tally_src_file);

答案 2 :(得分:0)

你可以试试这可能对你有帮助

您的代码是:

 $file_type = $_FILES['uploadedfile']['type'];
 $allowed = array('text/csv','text/comma-separated-values');

允许的类型数组会出现问题  你定义它像

$allowed = array('csv','txt','jpg');

请记住为您上传文件的文件夹授予777权限。 我认为它会起作用。

因为建议不要使用$_FILES['file']['type'] 代替你可以使用

$ext =  filetype ( string $filename );

它返回文件扩展名。

可以参考:http://php.net/manual/en/function.filetype.php

我希望它会对你有所帮助!

答案 3 :(得分:0)

我建议你使用codeigniter上传库。 https://ellislab.com/codeigniter/user-guide/libraries/file_uploading.html

- &GT;确保您上传的路径是真实可写的 - &GT;转储您的$_FILES并查看它是否显示正确的值和数组索引

以上是我上传时的示例代码:

if (isset($_FILES['userfile']) && is_uploaded_file($_FILES['userfile']['tmp_name'])) {

        $config['upload_path'] = $path = 'Your Path'; //MAKES SURE THIS PATH IS WRITABLE AND A REAL PATH
        $config['allowed_types'] = 'csv';
        $config['max_size'] = '100';
        $config['max_width']  = '1024';
        $config['max_height']  = '768';
        $config['remove_spaces']  = true;
        $config['overwrite']  = true;
        $config['encrypt_name']  = true;

        $this->load->library('upload', $config);

        if ( ! $this->upload->do_upload())
        {
            //error in upload
            var_dump($this->upload->display_errors());
        }
        else
        {
            //success upload
            var_dump($this->upload->data());
        }
    }