Jump to content

Creating a new file with PHP


Flames

Recommended Posts

My current code is the following (it is implemented with ajax so that's why its coded like that)

function create() {
if(isset($_POST['file']))
{
$file = $_POST['file'];
}
if(file_exists($file)) {
echo "File already exists, please edit the existing file or delete it and try and create this file again.";
die();
}
if ($fh = fopen ($file, "w")) { // line 108
            fclose ($fh);
echo "File created successfully";
die();
}
echo "Could not create new file";
}

 

I get the error

 

Warning: fopen(...) [function.fopen]: failed to open stream: No such file or directory in ... on line 108

Could not create new file

 

all folders are chmodded 0751 apart from one which I changed to 0777 but that still doesnt work

 

Any help would be appreciated

Link to comment
https://forums.phpfreaks.com/topic/187429-creating-a-new-file-with-php/
Share on other sites

Well as the error says 'no such file or directory'; double check the file name and path. Could you show an example of the file string you're passing in? I'm guessing (assuming the file is definitely there) you're using an absolute path, or it's something of that nature.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.