drmeu26880 2019-08-05 13:38
浏览 176
已采纳

Phalcon moveTo函数是不是将文件移动到服务器中的目标目录?

I'm trying to upload an image to a specific directory but the function moveTo is not moving the image.

public function uploadRecipeImageAction() {
    if ($this->request->hasFiles() == true) {
        $file = $this->request->getUploadedFiles()[0];
        $target_file = '/uploads/ketogenic-recipes/'.preg_replace("/[^a-z0-9\_\-\.]/i", '', basename($file->getName()));
        $file->moveTo($_SERVER['DOCUMENT_ROOT'] . $target_file);
    }
    return $target_file;
}

The function works fine locally but it's not working in server. There are no errors in logs

uploads and ketogenic-recipes directory permissions are set to 0775

PHP Version 7.2.20

Phalcon version is 3.4

var_dump($_SERVER['DOCUMENT_ROOT']) = string(30) "/home/web/public_html/test2"
var_dump($target_file); = string(42) "/uploads/ketogenic-recipes/harrypotter.jpg"
  • 写回答

1条回答 默认 最新

  • douzhaishan5462 2019-08-08 15:19
    关注

    We moved from old server to new server. And I found few wrong configurations which was the reason for not moving images/files to target directories.

    PHP-FPM was not enabled

    Our site was running on PHP 7.2.20 but PHP-FPM was not enabled on our website. So this means it was not using site specific php.ini

    Wrong home directory

    I mistakenly set home path for the sub-domains in cPanel. They were pointing to the sub-domain root instead of the web folder ( in phalcon we have web as home directory ). So $_SERVER['DOCUMENT_ROOT'] was pointing to the root folder; not to the web folder.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 metadata提取的PDF元数据,如何转换为一个Excel
  • ¥15 关于arduino编程toCharArray()函数的使用
  • ¥100 vc++混合CEF采用CLR方式编译报错
  • ¥15 coze 的插件输入飞书多维表格 app_token 后一直显示错误,如何解决?
  • ¥15 vite+vue3+plyr播放本地public文件夹下视频无法加载
  • ¥15 c#逐行读取txt文本,但是每一行里面数据之间空格数量不同
  • ¥50 如何openEuler 22.03上安装配置drbd
  • ¥20 ING91680C BLE5.3 芯片怎么实现串口收发数据
  • ¥15 无线连接树莓派,无法执行update,如何解决?(相关搜索:软件下载)
  • ¥15 Windows11, backspace, enter, space键失灵