Click to See Complete Forum and Search --> : File creation
CodeGod
01-02-2004, 01:18 AM
Hello all,
Can anyone provide me a solution?
The question is,
There are two URLs:
URL A= http://xyz.com/abc
URL B= http://abc.com/file_creator_script.php
Description of URL A:
The directory abc is world writable (CHMOD 0777)
Description of URL B:
The file file_creator_script.php is a PHP script which will write (create) a file ( file.php )in http://xyz.com/abc (URL A) when it is called in a web browser.
Like, if we load URL B in a web browser, on page load a file file.php will be automatically created in the URL A
I think the question is now explained.
I am waiting for replies anxiously. Please don't ask why do I need this. If you do help me, I'll be grateful.
P.S. By the way, I need this to manage data between two domains hosted on different machines.
Thank you!
Sux0rZh@jc0rz
01-02-2004, 01:30 AM
file creator script uploads all information needed to create said file into a mysql database.. then you add a script on URL A that reads the mysql and creates the file based on the information found in the file. you have the original file creator script open upload the information to the mysql database, then have it redirect to the file creator on URL A that creates a file using the last input added to the database.
would this system work for you?
NOTE: not sure because im still learning php and havent used file creation yet, but im think if u used my method, you wouldnt have to have ABC world writable, which would remove a hell of a lot of security risks.
CodeGod
01-02-2004, 01:44 AM
Dear Sux0rZh@jc0rz,
thanks for the quick reply. My problem is I don't have mysql installed on both machines.
I need to create the file.php in URL A only using the URL B.
I can not involve MySQL Database, mybe in the future but currently I have to create files via scripts.
Please think over it and suggest me.
Thanks :)
Sux0rZh@jc0rz
01-02-2004, 01:49 AM
mysql doesnt have to be installed on both machines. actually having it on both machines would be useless. you can connect to mysql from another machine, or you could simply get a free remote mysql host (http://www.freesql.org) ... all you need is php installed on URL A, and PHP + MYSQL on URL B..
perhaps using php's ftp functions you could do what you want. create the file then move it using an ftp function. like i said im still learning php so im not sure. im just good at solving problems, not the master coder. i can think things out but then making it happen is where i fall short. let me go read up on the ftp part to see if that would work.(the file transaction happens within the script so it wouldnt be a security risk)
Sux0rZh@jc0rz
01-02-2004, 02:00 AM
ftp info:
connecting (http://www.php.net/manual/en/function.ftp-connect.php)
uploading files (http://www.php.net/manual/en/function.ftp-put.php)
changing directories (http://www.php.net/manual/en/function.ftp-chdir.php)
close connection (http://www.php.net/manual/en/function.ftp-close.php)
Alright, well heres a script(taken directly from documentation then modified) that will upload the file once you make it.
<?php
$file = 'somefile.txt'; // this is the file you created.
$remote_file = 'readme.txt'; // this is what it will be called when u upload it to URL A.
$ftp_server = "servername"; // URL A's domain. (abc.com, not ftp://ftp.abc.com)
$ftp_user_name = "name"; // URL A's ftp username
$ftp_user_pass = "pass"; // URL A's ftp password
// set up basic connection
$conn_id = ftp_connect($ftp_server);
// login with username and password
$login_result = ftp_login($conn_id, $ftp_user_name, $ftp_user_pass);
// try to change the directory to abc
if (ftp_chdir($conn_id, "abc")) {
__ echo "Current directory is now: " . ftp_pwd($conn_id) . "\n";
} else {
__ echo "Couldn't change to abc directory\n";
}
// upload a file
if (ftp_put($conn_id, $remote_file, $file, FTP_ASCII)) {
_echo "successfully uploaded $file\n";
} else {
_echo "There was a problem while uploading $file\n";
}
// close the connection
ftp_close($conn_id);
?>
Sux0rZh@jc0rz
01-02-2004, 02:09 AM
note on above method: because ftp is used, you can remove the chmod from /abc. reducing SEVERE security risks.
ALSO: i cannot help you at all with the file creator.php because u have not given me enough information... what should the file contain? also, will you be creating multiple files? if so you will have to find a way to give them unique names when uploading... (i can do this multiple ways depending on what this script is for) and what is the file for? i need more information, k?
CodeGod
01-02-2004, 02:52 AM
For the test, Let's try to create only one file.
*.php and its content can be anything... variable, a text paragraph etc...
Thank you very much for your concern!
Sux0rZh@jc0rz
01-02-2004, 02:35 PM
k. srry last night i was up to 4:50 and for some reason it didnt show your last post until now. anways, i know nothing about file creation, so let me go read up on it.
Sux0rZh@jc0rz
01-02-2004, 02:55 PM
file info:
opening file (http://www.php.net/manual/en/function.fopen.php)
writing to a file (http://www.php.net/manual/en/function.fwrite.php)
<?PHP
fopen("c:\\data\\info.txt", "x"); // create file, if file exists, will throw error.
<insert file code here>
?>
Note: (taken from documentation) Different operating system families have different line-ending conventions. When you write a text file and want to insert a line break, you need to use the correct line-ending character(s) for your operating system. Unix based systems use \n as the line ending character, Windows based systems use \r\n as the line ending characters and Macintosh based systems use \r as the the line ending character.
ok pyro, if he needs help with further file creation, i think you'll have to help him, as i've absorbed to much information today. gotta let it all sink in or else i'll forget it.