第一次在这里发布。我正在尝试编写一个PHP脚本,该脚本将复制某些pdf文件并将其发送到服务器。我有一个查询,它将从其中提取需要发送的pdf的ID号。现在,我不知道该脚本是否未正确连接或该脚本未获取任何内容。另外,我在脚本底部进行了检查测试,以查看pdf是否已成功发送。任何帮助,将不胜感激。 PS:我收到以下错误信息:行:Zend_Db_Table :: getDefaultAdapter()-> update(“ transfers”,array(“ transfer_status” => 0),array(“ id =?” = > $ id [0]));
public function transfertoAction(){
$time_start = microtime(true);
$errors = array();
$data = Zend_Db_Table::getDefaultAdapter()->fetchAll("
SELECT id
FROM transfers
LIMIT 1
");
foreach ($data as $id) {
$srcBookChapter = "/var/www/sites/CDN/pdfs/$id.pdf";
$dstBookChapter = "/name/wheretopaste";
$ftpUsername = "username";
$ftpUserpass = "userpass";
$ftpServer = "server";
$ftpPort = "22";
$connection = ssh2_connect($ftpServer, $ftpPort);
ssh2_auth_password($connection, $ftpUsername, $ftpUserpass);
try {
if (!file_exists($srcBookChapter)) {
throw new Exception("Could not find file: $srcBookChapter");
}
$sftpStream = fopen("ssh2.sftp://".$sftp.$dstBookChapter, 'w');
if (!$sftpStream) {
throw new Exception("Could not open remote file: $dstBookChapter");
}
if (!file_exists($srcBookChapter)) {
throw new Exception("Could not find file: $srcBookChapter");
}
$data_to_send = file_get_contents($srcBookChapter);
if ($data_to_send === false) {
throw new Exception("Could not open local file: $dstBookChapter.");
}
if (fwrite($sftpStream, $data_to_send) === false) {
throw new Exception("Could not send data from file: $dstBookChapter.");
}
Zend_Db_Table::getDefaultAdapter()->update("transfers", array("transfer_status" => 1), array("id = ?" => $id[0]));
fclose($sftpStream);
} catch (Exception $e) {
Zend_Db_Table::getDefaultAdapter()->update("transfers", array("transfer_status" => 0), array("id = ?" => $id[0]));
$error = ('Exception: ' . $e->getMessage());
$errors[] .= $error;
}
}
$time_end = microtime(true);
$time = $time_end - $time_start;
zdd('Finished in ' . $time . ' seconds');
zddd('Done');
}