【问题标题】:chmod(): No such file or directorychmod():没有这样的文件或目录
【发布时间】:2017-07-04 03:33:17
【问题描述】:

这可能是重复的,但不知道我收到此错误的原因.. 当我使用另一台 php 版本为 5.6 的笔记本电脑时,此代码很好,但当我使用 php 版本为 5.4 的笔记本电脑时,我得到了一个错误。 . 这是我使用的代码..

        public function uploadImg($file, $newname){

            $path = "../valenciamd/captured_images/";
            $fileparts = pathinfo($file["name"]);
            $name =  $newname . $fileparts["extension"];

            if( is_dir($path) === false ){
                mkdir($path);
            }

            $i = 0;
            $parts = pathinfo($name);
            // while (file_exists($path . $name)) {
            //     $i++;
            //     $name = $parts["filename"] . "-" . $i . "." . $parts["extension"];
            // }
            $name = $parts["filename"]. "." . $parts["extension"];
            $success = move_uploaded_file($file["tmp_name"],
                $path . $name);

            chmod($path . $name, 0777);

            return $path . $name;
        }

$img = $reg->uploadImg( $_FILES['image'], $patientID.'.');

【问题讨论】:

  • 你能确认文件确实上传到指定路径并且存在吗?
  • 我已经检查了文件是否已上传但我没有看到任何内容..

标签: php file-upload chmod


【解决方案1】:

你确定你的 php 版本是 5.4,也许它低于 5.2 $path_parts['filename'] 是从 php 5.2 开始添加的,所以你什么也得不到。这不是错误,只需更新您的 php 版本即可。

或者如果你不想更新你的 php 版本,你可以使用 $parts['basename'] 而不是 $parts["filename"]. "." . $parts["extension"]

【讨论】:

    【解决方案2】:

    尝试使用递归目录创建
    阅读mkdir手册http://php.net/manual/en/function.mkdir.php

    bool mkdir ( string $pathname [, int $mode = 0777 [, bool $recursive = 假 [, 资源 $context ]]] )

    【讨论】:

      猜你喜欢
      • 2013-01-16
      • 2021-02-24
      • 2020-08-18
      • 1970-01-01
      • 2015-10-06
      • 2016-12-26
      • 2017-03-21
      • 2021-06-24
      • 2015-02-20
      相关资源
      最近更新 更多