Image permissions after uploading for resize

限于喜欢 提交于 2019-12-04 22:11:01

问题


I am having a user's profile page in which user uploads his profile picture from file dialog..

when the file is moved to my local server's folder it gets permission as 0644 only..

but I want to resize this image before getting uploaded into server...

And for this I need permission as 0777 to edit it...

How should I do it..

here is my code for move and resize

  $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..


回答1:


You need to run this on the files:

chmod ($filepath, 0777);

in your case probably:

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



回答2:


add this code with your absolute path

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

hope this will sure help you




回答3:


you need to add this line after move_uploaded_file function to set 777 permission for the uploaded file

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


来源:https://stackoverflow.com/questions/19492932/image-permissions-after-uploading-for-resize

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!