Browse Source

Adding support for multiple file upload using URLs

Previously only one URL was supported.
main
Benjamin Southall 7 years ago
committed by -
parent
commit
f3b833a3de
  1. 26
      post.php
  2. 5
      templates/post_form.html

26
post.php

@ -523,8 +523,14 @@ if (isset($_POST['delete'])) {
$_POST['subject'] = '';
}
if ($config['allow_upload_by_url'] && isset($_POST['file_url']) && !empty($_POST['file_url'])) {
$post['file_url'] = $_POST['file_url'];
if ($config['allow_upload_by_url'] && isset($_POST['file_url1']) && !empty($_POST['file_url1'])) {
function unlink_tmp_file($file) {
@unlink($file);
fatal_error_handler();
}
function upload_by_url($config,$post,$url) {
$post['file_url'] = $url;
if (!preg_match('@^https?://@', $post['file_url']))
error($config['error']['invalidimg']);
@ -543,10 +549,6 @@ if (isset($_POST['delete'])) {
error($config['error']['unknownext']);
$post['file_tmp'] = tempnam($config['tmp'], 'url');
function unlink_tmp_file($file) {
@unlink($file);
fatal_error_handler();
}
register_shutdown_function('unlink_tmp_file', $post['file_tmp']);
$fp = fopen($post['file_tmp'], 'w');
@ -569,13 +571,20 @@ if (isset($_POST['delete'])) {
fclose($fp);
$_FILES['file'] = array(
$_FILES[$post['file_tmp']] = array(
'name' => basename($url_without_params),
'tmp_name' => $post['file_tmp'],
'file_tmp' => true,
'error' => 0,
'size' => filesize($post['file_tmp'])
);
}
for( $counter = 1; $counter <= $config['max_images']; $counter++ ) {
$varname = "file_url". $counter;
upload_by_url($config,$post,$_POST[$varname]);
}
}
$post['name'] = $_POST['name'] != '' ? $_POST['name'] : $config['anonymous'];
@ -991,8 +1000,7 @@ if (isset($_POST['delete'])) {
escapeshellarg($file['thumb']));
if ($error){
$path = sprintf($config['file_thumb'],isset($config['file_icons'][$file['extension']]) ? $config['file_icons'][$file['ext
ension']] : $config['file_icons']['default']);
$path = sprintf($config['file_thumb'],isset($config['file_icons'][$file['extension']]) ? $config['file_icons'][$file['extension']] : $config['file_icons']['default']);
}
$file['thumb'] = basename($file['thumb']);

5
templates/post_form.html

@ -149,7 +149,10 @@
{% if config.allow_upload_by_url %}
<div style="float:none;text-align:left" id="upload_url">
<label for="file_url">{% trans %}Or URL{% endtrans %}</label>:
<input style="display:inline" type="text" id="file_url" name="file_url" size="35">
{% for counter in 1..config.max_images %}
<input style="display:inline" type="text" id="file_url{{ counter }}" name="file_url{{ counter }}" size="35">
</br>
{% endfor %}
</div>
{% endif %}
{{ antibot.html() }}

Loading…
Cancel
Save