dongping1689 2015-07-19 00:42
浏览 33

move_uploaded_file()不会移动文件

I have a class by the name of Input. Within this class is a function called iData. This function is used to get file upload data, here's the function.

public static function iData($item, $spec = '')
{
    if (isset($_FILES[$item])) {
        if ($spec == '') {
            return $_FILES[$item];
        }else{
            $f = $_FILES[$item];
            if($f[$spec]) {
                return $f[$spec];
            }
        }
    }
    return false;
}

But in my controller(By the way I'm using the MVC design pattern), when I tell it to move the file it doesn't. Here's my controller's code.

if (!empty(Input::iData('file', 'name'))) {
    if (is_dir('assets/')) {
        if (move_uploaded_file(Input::iData('file', 'name'), 'assets/')) {
            echo "File was moved!";
        } else {
            echo "File failed to move!";
        }
    }
} else {
    echo "Please include a file to upload!";
}

My page echos, "File failed to move!". So if the directory exists and I know that the Input class and iData function return the name, what is wrong?

  • 写回答

1条回答 默认 最新

  • duan198409 2015-07-19 00:56
    关注

    All is fixed. Much thanks to Hobo Sapiens

    I was supposed to use the tmp_name instead of the name. And also, I left the desired file name out of the move_uploaded_file's second parameter.

    评论

报告相同问题?

悬赏问题

  • ¥15 matlab 用yalmip搭建模型,cplex求解,线性化处理的方法
  • ¥15 qt6.6.3 基于百度云的语音识别 不会改
  • ¥15 关于#目标检测#的问题:大概就是类似后台自动检测某下架商品的库存,在他监测到该商品上架并且可以购买的瞬间点击立即购买下单
  • ¥15 神经网络怎么把隐含层变量融合到损失函数中?
  • ¥15 lingo18勾选global solver求解使用的算法
  • ¥15 全部备份安卓app数据包括密码,可以复制到另一手机上运行
  • ¥20 测距传感器数据手册i2c
  • ¥15 RPA正常跑,cmd输入cookies跑不出来
  • ¥15 求帮我调试一下freefem代码
  • ¥15 matlab代码解决,怎么运行