PDA

View Full Version : using fopen to create a php file


heaps21
08-03-2004, 09:57 PM
I am trying to use fopen with permissions set to w+ to create a php file as follows:

$filepath='http://www.tiptopvillas.com/property-in-'.$country_dir.'/property'.$prop_id.'.php/';
$newpropfile=fopen($filepath,"w+");


I get an error saying "Warning: fopen(http://www.tiptopvillas.com/property-in-NewZealand/property10017.php/): failed to open stream: HTTP wrapper does not support writeable connections."

Does this mean I have to use fopen differently to be able to create teh file, if so, how!

Any pointers much appreciated.

sad69
08-03-2004, 10:07 PM
Is this fopen script going to be run on the same server as these files you're going to be creating?

The reason I ask is because you can't create a file over the HTTP protocol. But if you have these files on the same server, then you should do something like the following:

$filepath='~/.www/property-in-'.$country_dir.'/property'.$prop_id.'.php/';
$newpropfile=fopen($filepath,"w+");


You'll probably have to change the path as necessary, but that should give you an idea of what's required.

As an aside, if the way you were trying to do it was possible, anyone could create files on different servers (not a good thing!). That's why they've got FTP to control user/passwords/privileges/... and all that.

Sadiq.

heaps21
08-03-2004, 10:15 PM
Is this fopen script going to be run on the same server as these files you're going to be creating?

Yes everything is on the 1 server


$filepath='~/.www/property-in-'.$country_dir.'/property'.$prop_id.'.php/';
$newpropfile=fopen($filepath,"w+");

You'll probably have to change the path as necessary, but that should give you an idea of what's required.

Sorry, I dont really understand the '~/.www/ bit of the filepath, what is that?

Thanks though, didnt think of it in terms of being able to create files on other servers!!

sad69
08-03-2004, 11:11 PM
Sorry, I dont really understand the '~/.www/ bit of the filepath, what is that?

Well that's *NIX stuff... sorry, wasn't sure what you were using..

Basically, relative to where the fopen script is going to be, the directory structure.

Sadiq.

heaps21
08-03-2004, 11:38 PM
Ah I see, that seems to work ok...ish - I have another question though(off topic?) if i am in a sub directory and i want the path to my home directory do i need to have the whole /home/../public_html/ or is there something that always relates to the home directory?

Cheers.

Jason
08-03-2004, 11:44 PM
the standard is '.' is for current directory '..' is for up one directory (if you are in a sub directory of home and you use '..' then you will be in the home dir) and '~' is home of the user ('~' roots home is / and the users home is /home/userName/ )

also if you want to simplify some steps like it sounds you do, you can make a symlink in the root directory to the base of those files so you would only need /linkName/..... to get to the files. Make sense?

Jason