TalkPHP
 
 
Account Login
Latest Articles
» The basic usage of PHPTAL, a XML/XHTML template library for PHP
» Vulnerable methods and the areas they are commonly trusted in.
» Simple way to protect a form from bot
» The Basics On: How Session Stealing Works
» How to keep your forms from double posting data
IRC Channel
IRC Speech Bubble Join the friendly bunch on IRC...
(#TalkPHP on Freenode)

...Also available via a web interface.

See this thread for information on the TalkPHP Free Hugs Initiative™. Subject to availability.
Associates
Associates
CSS Tutorials
Reply
 
LinkBack Thread Tools Search this Thread Display Modes
Old 08-11-2006, 07:01 PM   #1 (permalink)
The Visitor
 
BlackKite's Avatar
 
Join Date: Aug 2006
Location: Pennsylvania
Posts: 2
Thanks: 0
BlackKite is on a distinguished road
Default ftp_fput() Please Help

Hello,

My script is supposed to upload a temp file, create a new file and copy the contents of the temp file to the new one. Its doing all this so that I have permission to edit it in cpanel, if needed, once its created. Im having ftp_chmod chmod my public html file to 777 so it can make the files then close it back to 750. The script then chmods my index.php and posts a link to the new file on my navigation and closes it back to 644. Everything works fin except the creating and copying from the temp file thing.

For some reason its not creating what i think is the temp file, but instead creating a file with the name of one of my variables $ourFile. I've tried just about everything i can think of, and am hoping now that someone else will be able to help me out. Thanks!

Error:
Quote:
Warning: ftp_fput() [function.ftp-fput]: Rename/move failure: No such file or directory in /home/jaboo12/public_html/staff2/guide_p/game_p.php on line 52
Line 52:
PHP Code:
ftp_fput($connection$tempfile$bandleFTP_ASCII); 

My Code:
PHP Code:
<?php

        
//Check for file existence;

$ourFile $_POST['title'];

$filename "/home/jaboo12/public_html/$ourFile";
if (
file_exists("$filename")) {
   echo 
"The file $filename already exists. Please hit the back button and choose a new one";
  exit();
} else {
   echo 
"<center> Thank you for uploading your guide $ourLinkName ($ourFile). I has been posted to the neohound site. Please click <a href=\"http://www.neohound.com/staff2\">HERE</a> to returne to the staff panel.</center>";
}

        
//If it doesn't exist, login to FTP and chmod;

###########################
# ftp settings            #

$ftpServer='ftp.neohound.com'//ftp server, without ftp://
$ftpPort=21;                 //the ftp port (don't change if you don't know what it is)
$ftpUser='XXXXXX';         //ftp username
$ftpPass='XXXXXX';         //ftp password

# end ftp settings        #
###########################

###########################
# file settings           #

$tempfile '/home/jaboo12/public_html/temp.php';
$ftpdir 'public_html';
$nav 'public_html/index.php';
$file '/home/jaboo12/public_html/$ourFile';

# end file settings       #
###########################

//connect to server
$connection ftp_connect($ftpServer$ftpPort);
ftp_login($connection$ftpUser$ftpPass);

//chmod directory so that the server can create a file
ftp_chmod($connection0777$ftpdir);

//make temporary file
$handle fopen("$tempfile"'w');
fclose($handle); 

//upload file using ftp
$bandle fopen("$file"'w');
ftp_fput($connection$tempfile$bandleFTP_ASCII);
fclose($bandle);

//delete temporary file
unlink($tempfile); 


$ourFileName $_POST['name'];

$ourLinkName $_POST['link'];

        
//Post content feild to the file created;

$myFile "/home/jaboo12/public_html/$ourFile";
$fh fopen("$myFile"'w') or die("can't open file");

$content $_POST['content'];
$help stripslashes ($content);
$newcontent strip_tags($help'<img><div></div><font></font><p></p><br></br><hr></hr><a></a><b></b><i></i><u></u>');
fwrite ($fh$newcontent);
fclose($fh);

//reset directory permissions
ftp_chmod($connection0750$ftpdir);



        
//Post navigation link on index;

//chmod directory so that the server can create a file
ftp_chmod($connection0777$nav);


$newLink "<br> » <a href=\"http://www.neohound.com/index.php?id=$ourFileName\">$ourLinkName</a>

<!-- game -->"
;

$data file_get_contents('/home/jaboo12/public_html/index.php');

$data str_replace ('<!-- game -->'$newLink$data);

$fp fopen ("/home/jaboo12/public_html/index.php"'w');
fwrite ($fp$data);
fclose ($fp);


//reset directory permissions
ftp_chmod($connection0644$nav);

//close connection
ftp_close($connection);  

?>
__________________
eTrast Hosting
Quality Inexpensive Websites
Send a message via MSN to BlackKite Send a message via Yahoo to BlackKite
BlackKite is offline  
Reply With Quote
Old 08-12-2006, 05:36 PM   #2 (permalink)
The Wanderer
 
Join Date: Mar 2005
Posts: 17
Thanks: 0
mikem is on a distinguished road
Default

Are the files being stored on the same account as your script is installed on? If so you could just use the $_FILES array to find out where the temp file is saved to then move it to the directory of your choice.
__________________
Mike
::Shrapnel-Network::
www.shrapnet.com
mikem is offline  
Reply With Quote
Old 08-12-2006, 09:47 PM   #3 (permalink)
The Visitor
 
BlackKite's Avatar
 
Join Date: Aug 2006
Location: Pennsylvania
Posts: 2
Thanks: 0
BlackKite is on a distinguished road
Default

Well it's supposed to be getting stored in my public html "$tempfile = '/home/jaboo12/public_html/temp.php'". Is that wrong?
__________________
eTrast Hosting
Quality Inexpensive Websites
Send a message via MSN to BlackKite Send a message via Yahoo to BlackKite
BlackKite is offline  
Reply With Quote
Reply



Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
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
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 06:22 PM.

 
     

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0
Inactive Reminders By Icora Web Design