Jump to content

Recommended Posts

to simply create the filename, something like this:

 

$filename = $_POST['username'];

 

now, if you're looking to create the file, name the file, access the file, etc., you need to be more specific with your questions.  otherwise, hope that helps.

Thanks for the reply but it did not work for me.

I am creating the file name to store the form values using the name provided by the user.

Suppose if there is a user with name "Peter" then I want the file name created in his name like "Peter.txt". I hope this should help you people to help me with the code.

 

Thanks

 

Thanks.

It worked by using the code

$file=$name;

 

But I want the filename in a particular directory like PHP/Peter.txt. This is not happening even though I set the permissions of the file and the directory. It displays an error "fopen cannot open directory: Is a directory /PHP/Peter.txt ". Could anyone please help me with this.

 

 

what os are you using for your server?

 

also, i may be wrong but i believe you need to set a flag for creating the file if it does not exist.

 

try "w" eg

 

<?php
$handle = fopen("/PHP/" . $file , "w");
?>

 

or change the flag to just "r+" if you dont want to overwrite it, eg simply append it.

firstly, you should put quotes around the flag. Not required, but that is probably drawing a Notice message.

 

secondly, look at what the error says "fopen cannot open directory"

 

what do you think that means? you will need to make that directory before you add files to it. are you sure that directory exists?

Yes I have already given "a" in the fopen.

I am very sure the directory is created and even the permissions to access it are set but still it is giving me warning but still it wont allow it to create too.

 

Warning: fopen(PHP): failed to open stream: Is a directory in /home/ram/public_htmlPHP/formfile.php on line 24

 

Warning: fclose(): supplied argument is not a valid stream resource in /home/ram/public-html/PHP/formfile.php on line 34

 

 

 

When I used only fopen function with the flags set to it, it did not allow me to store the contents in the file too. I had to use getFileName($path) and then it worked but now it is not allowing me to store into the directory too whatever I do.

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.