Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I create file on server?

Tags:

php

Let say I want create file call style.css in /css/ folder.

Example : When I click Save button script will create style.css with content

 body {background:#fff;}
 a {color:#333; text-decoration:none; }

If server cannot write the file I want show error message Please chmod 777 to /css/ folder

Let me know

like image 370
Unknown Error Avatar asked Sep 02 '26 19:09

Unknown Error


2 Answers

$data = "body {background:#fff;}
a {color:#333; text-decoration:none; }";

if (false === file_put_contents('/css/style.css', $data))
   echo 'Please chmod 777 to /css/ folder';
like image 128
linepogl Avatar answered Sep 05 '26 12:09

linepogl


You can use the is_writable function to check whether the file is writable or not.

For example:

<?php
$filename = '/path/to/css/style.css';
if (is_writable($filename)) {
    echo 'The file is writable';
} else {
    echo 'Please chmod 777 to /css/ folder';
}
?>
like image 20
Luca Matteis Avatar answered Sep 05 '26 12:09

Luca Matteis