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 有没有人会打学生成绩管理系统呀
  • ¥15 在使用Fiddler和夜神模拟器抓包的时候一直出现443该怎么办啊QAQ搜了好几个笔记都没有解决
  • ¥15 3x7的二维数组A、B、C,A中的任意1个数组元素与B的任意1个数组元素、同时又与C的任意1个数组元素比较,把不同位置出现相同数的比较称为无意义,反之称为有意义,把有意义的比较打印输出。
  • ¥20 预测模型怎么处理原始数据(随机森林)
  • ¥20 请问discuz3.5如何实现插入ckplayer全能播放器功能呢?
  • ¥15 thingsboard代码编译出错误
  • ¥15 博途v18仿真报错怎么解决
  • ¥15 欧姆龙plc枕式包装机 ST编程
  • ¥15 为啥快手广告联盟的广告这么难出来
  • ¥15 k8s集群重启后,kubelet一直报systemctl restart kubelet.service "Failed to delete cgroup paths"