Give 777 permission to dynamically created file in php

Rohit Goel picture Rohit Goel · Jan 7, 2013 · Viewed 44.7k times · Source

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);

 ?>

Answer

Alessandro Minoccheri picture Alessandro Minoccheri · Jan 7, 2013

Use the function chmod
chmod

$fp = fopen($file, 'w');
fwrite($fp, $content);
fclose($fp);
chmod($file, 0777);