By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
435,512 Members | 3,847 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,512 IT Pros & Developers. It's quick & easy.

ftp_fput() error help

P: 2
I have this script I wrote up as a php backend. But its throwing some errors i dont quite understand. Hope someone can help me fix this. Please

Error:
Warning: ftp_fput() expects parameter 2 to be string, resource given in /home/jaboo12/public_html/staff2/guide_p/game_p.php on line 52
Line 52:
[PHP]ftp_fput($connection, $bandle, $file, FTP_ASCII);[/PHP]

Whole Code:
[PHP]<?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='jaboo12'; //ftp username
$ftpPass='staycool'; //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($connection, 0777, $ftpdir);

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

//upload file using ftp
$bandle = fopen("$tempfile", 'r');
ftp_fput($connection, $bandle, $file, FTP_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($connection, 0750, $ftpdir);



//Post navigation link on index;

//chmod directory so that the server can create a file
ftp_chmod($connection, 0777, $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($connection, 0644, $nav);

//close connection
ftp_close($connection);

?>[/PHP]
Aug 6 '06 #1
Share this Question
Share on Google+
2 Replies


bevort
P: 53
You get this error because the var $bandle does not exist

I think you made an error typing the $handle var, you typed $bandle with a B instead.

Vincent
Aug 7 '06 #2

P: 2
no, lol, i put bandle becuase i already had another handle and i thought that might of been causing the problem.


$bandle = fopen("$tempfile", 'r');

ftp_fput($connection, $bandle, $file, FTP_ASCII);

fclose($bandle);
Aug 7 '06 #3

Post your reply

Sign in to post your reply or Sign up for a free account.