Webmaster Forums 101 - Free Help and Discussions
 
 
 

MEMBER REWARDS - Earn free advertising by participating in these forums! Click here for details.

Welcome to Webmaster Forums 101!

You are currently viewing our boards as a guest which gives you limited access to view most discussions, articles and access our other FREE features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload your own photos and access many other special features. Registration is fast, simple and absolutely free so please, join our community today!

If you have any problems with the registration process or your account login, please contact contact support.

Reply
 
Thread Tools Search this Thread Display Modes
Old 14th March 2005, 12:41 PM   #1

Username: Ben
Rank: WF101 Fanatic
Join Date: Jan 2005
Posts: 181
Points: 26.24
Default FTP and Creating New Files

Hey there,

I have written a PHP script that can create, edit and delete PHP files on the web server.

My script is used on my clients websites which use CPanel, so all of the files and folders are saved in the /public_html/ folder.

I currently use this code to create a file in the /public_html/ folder:

PHP Code:
<?php
$fp
=fopen("filename.php",w);
fputs($fp,$content);
fclose($fp);
?>
Which works fine ONLY if the /public_html/ folder is CHMODed to 777. However, their host have an automatic script that changes the CHMOD of the /public_html/ folder to 750 resulting in my script not being able to create files. Is there a way to create new files without having the /public_html/ folder set to 777?
Ben is offline   Reply With Quote
Old 15th March 2005, 02:58 PM   #2
Mr. Tech's Avatar

Username: Mr. Tech
Rank: Problem Solver
Join Date: Dec 2004
Location: Gold Coast, Australia
Posts: 2,166
Points: 1,025.61
Send a message via MSN to Mr. Tech
Default

There's a potential to ftp it into the folder... just write the file to a writable location (like a temporary folder or something) then ftp it into place. It is not possible to create a file using FTP. Doesn't make sense to me...
__________________
Please read the Forum Rules

Get rewarded for posting
- free advertising!

.::. [ Webmaster Resources ] .::. [ Web Design ] .::. [ Developer Tutorials ] .::.
Mr. Tech is offline   Reply With Quote
Old 15th March 2005, 03:01 PM   #3

Username: Ben
Rank: WF101 Fanatic
Join Date: Jan 2005
Posts: 181
Points: 26.24
Default

Sounds liek a smart idea. I do happen to have some code for moving fields using ftp but it doesn't work.... See below

PHP Code:
<?php
$ftp_server 
"";
$ftp_user_name ""
$ftp_user_pass "";
$destination_file "/public_html/ftptest/file.html";
$source_file "/public_html/test.html";
 
// 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);
 
// check connection
if ((!$conn_id) || (!$login_result)) {
echo 
"FTP connection has failed!";
echo 
"Attempted to connect to $ftp_server for user $ftp_user_name";
exit;
} else {
echo 
"Connected to $ftp_server, for user $ftp_user_name";
}
 
// upload the file
$upload ftp_put($conn_id$destination_file$source_fileFTP_BINARY);
 
// check upload status
if (!$upload) {
echo 
"FTP upload has failed!";
} else {
echo 
"Uploaded $source_file to $ftp_server as $destination_file";
}
 
// close the FTP stream
ftp_close($conn_id);
 
?>

It says it connects to the server ok but I always get the FTP upload has failed! error and this error:

Warning: ftp_put(): open_basedir restriction in effect. File(/public_html/test.html) is not within the allowed path(s): (/home/openviews/:/usr/lib/php:/usr/local/lib/php:/tmp) in /home/openviews/public_html/ftptest/test.php on line 24

I dont get the above error when I remove the slash (/) infront of the source and destination file but I still get the failed error.

Is there something wrong with my code? I copied it directly from the PHP website...
Ben is offline   Reply With Quote
Old 15th March 2005, 03:02 PM   #4
Mr. Tech's Avatar

Username: Mr. Tech
Rank: Problem Solver
Join Date: Dec 2004
Location: Gold Coast, Australia
Posts: 2,166
Points: 1,025.61
Send a message via MSN to Mr. Tech
Default

try:

/home/webmaste/public_html/test.html

/public_html isn't a valid path.
__________________
Please read the Forum Rules

Get rewarded for posting
- free advertising!

.::. [ Webmaster Resources ] .::. [ Web Design ] .::. [ Developer Tutorials ] .::.
Mr. Tech is offline   Reply With Quote
Old 15th March 2005, 03:03 PM   #5

Username: Ben
Rank: WF101 Fanatic
Join Date: Jan 2005
Posts: 181
Points: 26.24
Default

W00t it worked!

yes your suggestion worked mr tech, thanks!

$destination_file = "/public_html/ftptest/test.html";
$source_file = "/home/openviews/public_html/test.html";
Ben is offline   Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Forum Jump

Login
User Name
Password


Featured Members


Featured Links


Useful Resources
Webmaster Resources
Developers Tools
Developer Tutorials


Partners

All times are GMT +10. The time now is 08:54 AM.


Powered by vBulletin Version 3.5.2
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 2.3.2
 
 
WEBMASTER FORUMS 101
ARCHIVE
CONTACT US
TOP
   
© Webmaster Forums 101 2005. All Rights Reserved.
Design by: vBCore