【问题标题】:Image permissions after uploading for resize上传调整大小后的图像权限
【发布时间】:2013-10-29 20:26:01
【问题描述】:

我有一个用户的个人资料页面,用户在该页面中从文件对话框上传他的个人资料图片..

当文件移动到我本地服务器的文件夹时,它只获得 0644 的权限..

但我想在上传到服务器之前调整此图像的大小...

为此,我需要 0777 的权限才能对其进行编辑...

我该怎么做..

这是我的移动和调整大小的代码

  $upload_dir = './images';
  $tmp = $_FILES["img"]["tmp_name"];
  $names = $_FILES["img"]["name"];
  $res=$moveR=move_uploaded_file($tmp, "$upload_dir/$names");

  $a="./images/".$names;        
  list($width, $height) = getimagesize($a);
  $newwidth = "300"; 
  $newheight = "200";
  $thumb = imagecreatetruecolor($newwidth, $newheight);
  $source = imagecreatefromjpeg($a);
  imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
  imagejpeg($thumb, $a, 100);

提前谢谢..

【问题讨论】:

    标签: php image file permissions chmod


    【解决方案1】:

    你需要在文件上运行这个:

    chmod ($filepath, 0777);
    

    在你的情况下可能:

    chmod("$upload_dir/$names",0777);
    

    【讨论】:

      【解决方案2】:

      用你的绝对路径添加这段代码

       $file_path = $path.'/files/ChatRequestXML/'.$profile_id.'.jpg'; // change with your actual path
              chmod($file_path, 0777);
      

      希望这对你有帮助

      【讨论】:

        【解决方案3】:

        需要在move_uploaded_file函数后面加上这一行来设置上传文件的777权限

        <?php
           exec("chmod $upload_dir/$names 0777");
        ?>
        

        【讨论】:

        • 直接从临时文件创建图像。替换 $a = $tmp 并替换 imagejpeg($thumb, $a, 100); with imagejpeg($thumb, $upload_dir/$names, 100);并删除行 $res=$moveR=move_uploaded_file($tmp, "$upload_dir/$names");
        猜你喜欢
        • 1970-01-01
        • 2023-03-18
        • 2013-02-09
        • 1970-01-01
        • 2011-12-23
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多