• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 672
  • Last Modified:

PHp Fwrite Fopen Name file with URL

How can I get php to create a file then write to it using
the URL for the name.


http://example.com/hey/you/

and the output file name would be

heyyou.txt


I have been at this for a while now.

Thnk you in advance.
$fp=fopen("comm.txt",'ab');
fwrite($fp,$outputstring);
fclose($fp);

Open in new window

0
selvol
Asked:
selvol
  • 2
  • 2
1 Solution
 
hawardenCommented:
parse_url($url, PHP_URL_PATH) should return "/hey/you" and then str_replace can be used to replace the "\" with "". Once you have the text version of the filename, appending the extension and writing out should be ok. Don't forget to give the full path before writing, including the complete directory structure:


$url = "http://example.com/hey/you/"
$filestr = str_replace( "/", "", parse_url($url, PHP_URL_PATH));
$fp=fopen("/home/user/myfiledump/$filestr",'ab');
fwrite($fp,$outputstring);
fclose($fp);

Open in new window

0
 
selvolAuthor Commented:
Yes, I apologize if was unclear.  
The problem I am having is    Grabbing The actual URL of the page.
As the $url in not known for it is dynamic.        


Something like  
$url = $_GET["_$request"];  .
How do I dynamically set the $url


Thank you.   


Selvol
0
 
hawardenCommented:
If you print out the contents of _GET with print_r, you should see a field that contains the full URL.

Off the top of my head, $_SERVER['QUERY_STRING'] might contain what you need. You can print it out to see. Sorry, I'm not near a web server at the moment to test it out right now.
0
 
selvolAuthor Commented:
Thank you.    I'll get it now.     


Regards.

$uri = $_SERVER['REQUEST_URI'];

echo $uri;

Open in new window

0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now