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 电力市场出清matlab yalmip kkt 双层优化问题
  • ¥30 ros小车路径规划实现不了,如何解决?(操作系统-ubuntu)
  • ¥20 matlab yalmip kkt 双层优化问题
  • ¥15 如何在3D高斯飞溅的渲染的场景中获得一个可控的旋转物体
  • ¥88 实在没有想法,需要个思路
  • ¥15 MATLAB报错输入参数太多
  • ¥15 python中合并修改日期相同的CSV文件并按照修改日期的名字命名文件
  • ¥15 有赏,i卡绘世画不出
  • ¥15 如何用stata画出文献中常见的安慰剂检验图
  • ¥15 c语言链表结构体数据插入