Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Give 777 permission to dynamically created file in php

Tags:

Hi i have a script which dynamically created a file on my local directory Please tell me how can i give 777 permission to that file right now it is unaccessible in the browser

<?php
//Get the file
$content = 'http://xxx.xxx.com.mx/media/catalog/product/cache/1/image/9df78eab33525d08d6e5fb8d27136e95/b/r/bridal-shoes1.jpg ';
$content1 = explode('/', $content);
$end = end($content1);
echo $end;
//print_r($content1[12]);
//Store in the filesystem.
$my_file = $end;
$handle = fopen($my_file, 'w') or die('Cannot open file:  '.$my_file); //implicitly creates file
$path = '/var/www/'.$end;

copy($content, $path);

 ?>
like image 227
Rohit Goel Avatar asked Jan 07 '13 09:01

Rohit Goel


People also ask

What permissions do PHP files need?

If you want read and write, it's 6 (4+2), and if you want all permissions, it's 7 (4+2+1). Most php files will have 644 because the owner has to be able to edit it, everyone needs to be able to read it, and nobody needs to execute it (in the strictly unix sense.

Which octal number is used for read and execute permission in PHP?

The parameter "mode" consists of three octal number components: access restrictions for the owner, user group in which the owner is in, and everybody else in this order. Number 1 means that we grant execute permissions, number 2 means that we make the file writeable, and number 4 means that we make the file readable.


1 Answers

Use the function chmod
chmod

$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
chmod($file, 0777); 
like image 124
Alessandro Minoccheri Avatar answered Oct 10 '22 20:10

Alessandro Minoccheri