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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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