creating a file on a remote server

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
psavvy
Forum Newbie
Posts: 2
Joined: Mon Oct 02, 2006 4:27 pm

creating a file on a remote server

Post by psavvy »

hi,
What is the best way to create a file on a remote server in php. Would fsocketsopen() be a way?
And if possible the files should be created with a username and password.. the same one i use login in with like a ftp client.
But this needs to be done with php. Any help would be much appreciated.
chocolatetoothpaste
Forum Newbie
Posts: 10
Joined: Wed Sep 06, 2006 10:48 am

Post by chocolatetoothpaste »

Just use

Code: Select all

$handle = fopen($filename, 'a');
fwrite($handle, $content);
It will try to write to a file, or create it if it doens't exist.

I don't know if you can give the file a username/password, but you could create a sub-folder for each user that is named after their user ID or some other identifier.
User avatar
Mordred
DevNet Resident
Posts: 1579
Joined: Sun Sep 03, 2006 5:19 am
Location: Sofia, Bulgaria

Post by Mordred »

If by "remote server" you mean a third party (the client and server being the natural two), you can try the ftp_* functions.
User avatar
Luke
The Ninja Space Mod
Posts: 6424
Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA

Post by Luke »

you need some sort of permission to create files on a remote server... do you have ftp access to this remote server?
psavvy
Forum Newbie
Posts: 2
Joined: Mon Oct 02, 2006 4:27 pm

Post by psavvy »

yes i have full access.

what i need to do is get content from a database, create an html page, and send it to another website/server whatever. the files need to be created there.

i'm just not sure what the best way is. if i use the ftp function that php provides, i'd first have to create a local file no?
Post Reply