...

View Full Version : Resolved ftp_fput



Phil Jackson
10-16-2009, 09:50 AM
Morning all im back.

here is my code:



$filesQuery = mysql_query("SELECT * FROM `files` ORDER BY id") or die(mysql_error());
$x=0;
$z=0;
$conn_id = ftp_connect($FTPhost);
$login_result = ftp_login($conn_id, $FTPuser, $FTPpass);

while($filesArray = mysql_fetch_array($filesQuery))
{
if($z==0)
{
if(!ftp_chdir($conn_id , $ROOT."/ACT.".md5($WEBSITE)."_stylesheets/"))
{
ftp_mkdir($conn_id, $ROOT."/ACT.".md5($WEBSITE)."_stylesheets/");
}
}
$pathFromRoot = $filesArray["files"];
$localPathFromRoot = "../../users/".md5($WEBSITE)."/".$pathFromRoot;

if(file_exists($localPathFromRoot))
{
$from = fopen($localPathFromRoot, 'r');
if(!ftp_fput($conn_id, $pathFromRoot, $from, FTP_BINARY))
{
$x++;
die("error uploading"); //added this for testing
}
fclose($from);
}
$z++;
}
ftp_close($conn_id);

if($x==0)
{
echo "<span style=\"green\">Files uploaded successfuly!</span>";
}
else
{
echo "<span style=\"red\">File upload failed!</span>";
}


this worked fine for about 2 mins then stopped working saying the following


Warning: ftp_fput() [function.ftp-fput]: public_html/e6b4e0d743dbabe2b59eecf807f4b536.txt: Not a directory in /home/sites/snowyswebsolutions.co.uk/public_html/scripts/php/publish.php on line 70

what i cant understand, public_html/e6b4e0d743dbabe2b59eecf807f4b536.txt being $pathFromRoot, why it returns true for file_exists but says it doesn't with ftp_fput?

Any ideas?

Phil Jackson
10-16-2009, 10:00 AM
it's ok, came too soon again.


if(!ftp_fput($conn_id, $pathFromRoot, $from, FTP_BINARY))
to
if(!ftp_fput($conn_id, "/".$pathFromRoot, $from, FTP_BINARY))



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum