上传后的图像权限用于调整大小

6

我有一个用户个人资料页面,用户可以从文件对话框上传他的个人资料图片。

当文件移动到我的本地服务器文件夹时,它只得到了 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);

Thanks in advance..

3个回答

1
您需要在这些文件上运行此代码:
chmod ($filepath, 0777);

在你的情况下可能是:

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

0

在move_uploaded_file函数之后添加此行以为上传的文件设置777权限

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

直接从临时文件创建图像。将 $a = $tmp 替换为 imagejpeg($thumb, $upload_dir/$names, 100); 并删除 imagejpeg($thumb, $a, 100); 这一行。同时移除 $res=$moveR=move_uploaded_file($tmp, "$upload_dir/$names"); 这一行。 - Prem

0
将这段代码添加到你的绝对路径中。
 $file_path = $path.'/files/ChatRequestXML/'.$profile_id.'.jpg'; // change with your actual path
        chmod($file_path, 0777);

希望这能确实帮到你


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接