我希望能够通过phpbb将远程文件上传到我的服务器,而无需先将文件下载到我的电脑上。如何实现这一目标?
我有一些简单的代码,我已经测试过它可以完成这项工作,但是我可以在哪里放置它以及我需要在phpBB中修改什么?
<form method="post">
<input name="url" size="50"/>
<input name="submit" type="submit"/>
</form>
<?php
// maximum execution time in seconds
set_time_limit(24 * 60 * 60);
if (!isset($_POST['submit'])) die();
// folder to save downloaded files to. must end with slash
$destination_folder = 'mydownloads/';
$url = $_POST['url'];
$newfname = $destination_folder . basename($url);
//Open remote file
$file = fopen($url, "rb");
if ($file) {
//Write to local file
$newf = fopen($newfname, "wb");
if ($newf) {
while (!feof($file)) {
fwrite($newf, fread($file, 1024 * 8), 1024 * 8);
}
}
}
if ($file) {
fclose($file);
}
if ($newf) {
fclose($newf);
}
?>
或者是否可以在phpBB中使用远程头像功能(即包含/ functions_upload.php - &gt;函数remote_upload($ upload_url))? 我当然需要通过通常的phpBB函数发送远程文件以插入数据库和所有。
答案 0 :(得分:4)
打开文件包含/ message_parser.php
查找第1373行
$upload_file = (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none' && trim($_FILES[$form_name]['name'])) ? true : false;
并替换为
$upload_file = (isset($_FILES[$form_name]) && $_FILES[$form_name]['name'] != 'none' && trim($_FILES[$form_name]['name'])) ? true : (!empty($_POST['urlupload'])) ? true : false;
打开文件包含/ functions_posting.php
找到第414行
$file = ($local) ? $upload->local_upload($local_storage, $local_filedata) : $upload->form_upload($form_name);
替换为
$file = ($local) ? $upload->local_upload($local_storage, $local_filedata) : (!empty($_POST['urlupload'])) ? $upload->remote_upload($_POST['urlupload']) : $upload->form_upload($form_name);
打开样式/ your_style / templates / posting_attach_body.html
找到
<dl>
<dt><label for="fileupload">{L_FILENAME}:</label></dt>
<dd>
<input type="file" name="fileupload" id="fileupload" maxlength="{FILESIZE}" value="" class="inputbox autowidth" />
<input type="submit" name="add_file" value="{L_ADD_FILE}" class="button2" onclick="upload = true;" />
</dd>
</dl>
后添加
<dl>
<dt><label for="urlupload">Remote File:</label></dt>
<dd>
<input type="url" name="urlupload" id="urlupload" maxlength="{FILESIZE}" value="" class="inputbox autowidth" />
<input type="submit" name="add_file" value="{L_ADD_FILE}" class="button2" onclick="upload = true;" />
</dd>
</dl>
如果您希望我创建一个用于使用automod进行安装的mod,或者如果您需要使用remote_upload函数的额外mime类型,请告诉我