开发者

PHP FTP upload not working

What I'm trying to do is automaticly upload a zip-file through FTP using PHP, and then extract the zip-file as well. However first things first: I'm having trouble with uploading the zip-file using PHP's ftp_put function. This is my script:

// set up basic connection
$conn_id = ftp_connect($ftp_server); 

// login with username and password
$login_result = ftp_login($conn_id, $user, $pass); //<!--same as cPanel account user 开发者_如何学运维and pass?

// check connection
if ((!$conn_id) || (!$login_result)) { 
    echo "FTP connection has failed!";
    echo "Attempted to connect to $ftp_server for user $user"; 
    exit; 
} else {
    echo "Connected to $ftp_server, for user $user";
}

// server & file info
$file = 'phpBB3.zip';
$ftp_root = '/public_html/';
$site_root = $_SERVER['DOCUMENT_ROOT'].'/scripts/';

// >>>HERE<<<
// upload the file
// >>>HERE<<<
$upload = ftp_put($conn_id, $ftp_root .$file, $site_root . $file, FTP_BINARY);

// check upload status
if (!$upload) { 
    echo "FTP upload has failed!";
} else {
    echo "Uploaded $file to $ftp_server as $file";
}

// unzip the uploaded file (from FTP?)
$unzip = shell_exec("unzip {$file}"); //<!-- how to do this through FTP uploaded files?

// close the FTP stream 
ftp_close($conn_id); 

What's happening here is that it (SOMETIMES) uploads A PART of the file ( always the same amount; like 900 kB ) and sometimes doesn't upload anything at all. It's as if the uploading process is interrupted by the rest of the script being executed while the uploading wasn't finished yet. Though I'm not sure if that's the cause of the problem.

Though, it always gives me this error:

Warning: ftp_put() [function.ftp-put]: Connecting to port 38694 in /home/quicksit/public_html/createacct.php on line 93

Where the output port is always different and always larger than 20.000 ( like 30.000-50.000 ).

Could anyone help me out on this?

Thanks in advanced, Skyfe.


There is a timeout and upload limit in the configuration file for PHP... you may want to check the setting there.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜