Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 250
  • Last Modified:

PHP Create and Save a file into a specified folder

Hi all,

I need to create a php file with php. It will contain php, html and js code. It will and save it to a specifed folder programmatically.

Can anyone provide a simple sample code please?

Thanks
0
error77
Asked:
error77
  • 2
  • 2
1 Solution
 
HellmarkCommented:
You say "It will and save it to a specifed folder programmatically.", but you do not specify what it will do.  Please provide more information.
0
 
Ray PaseurCommented:
You best friend here may be heredoc notation to create the string.  But this does not sound like anything we studied in computer science.  Where did you get the idea that you needed to do something like this?  Can you please step back from the technical description and just tell us in plain language what business question you are trying to solve?  Thanks, ~Ray
0
 
error77Author Commented:
Basically I have a php page which I could just copy to the folder BUT I need to slightly modify it each time I copy one to a folder. Things that change are user id etc ... so the php page will have it's variable values changed and saved as a new page.

Make sense now?
0
 
error77Author Commented:
I am trying this to start with:

$fh = fopen("/includes/myfile.txt", "w");

if($fh==false)
      die("unable to create file");

but all I get is "unable to create file" although the target directory is cmod 0777
0
 
Ray PaseurCommented:
The fopen() might need more accurate path information.  Check into the values you find with getcwd() and look into the output from phpinfo() near the bottom.

Looking at ID:37052083 I am wondering about the idea of saving multiple copies of a PHP script with different variable values.  Normally, programming is generalized -- made to work correctly on a set of variables.  The variables are given to the program script via GET or POST method requests.  In this way one program script can produce a variety of customized outputs, depending on the values of these external variables.  If you were working with HTML, which has no programmable aspects (it's not interpreted, just a string of characters) I could understand saving different copies, but with PHP I think the logical approach might be to write a program that works for the general case, and then send in the variables from an external source, perhaps in the URL.
0

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