Image permissions after uploading for resize

2019-03-27 20:52发布

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

3条回答
叛逆
2楼-- · 2019-03-27 21:35

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

查看更多
Animai°情兽
3楼-- · 2019-03-27 21:37

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");
?>
查看更多
狗以群分
4楼-- · 2019-03-27 21:39

You need to run this on the files:

chmod ($filepath, 0777);

in your case probably:

chmod("$upload_dir/$names",0777);
查看更多
登录 后发表回答