forked from leftypol/leftypol
parent
bc7fa47aa2
commit
a1f64335f9
3 changed files with 55 additions and 16 deletions
|
@ -2853,6 +2853,24 @@ function link_for($post, $page50 = false, $foreignlink = false, $thread = false)
|
||||||
return sprintf($tpl, $id, $slug);
|
return sprintf($tpl, $id, $slug);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Generate filename, extension, file id and file and thumb paths of a file
|
||||||
|
function process_filenames($file, $board_dir, $multiple, $i){
|
||||||
|
global $config;
|
||||||
|
$file['filename'] = urldecode($file['name']);
|
||||||
|
$file['extension'] = strtolower(mb_substr($file['filename'], mb_strrpos($file['filename'], '.') + 1));
|
||||||
|
if (isset($config['filename_func']))
|
||||||
|
$file['file_id'] = $config['filename_func']($file);
|
||||||
|
else
|
||||||
|
$file['file_id'] = time() . substr(microtime(), 2, 3);
|
||||||
|
|
||||||
|
if ($multiple)
|
||||||
|
$file['file_id'] .= "-$i";
|
||||||
|
|
||||||
|
$file['file'] = $board_dir . $config['dir']['img'] . $file['file_id'] . '.' . $file['extension'];
|
||||||
|
$file['thumb'] = $board_dir . $config['dir']['thumb'] . $file['file_id'] . '.' . ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension']);
|
||||||
|
return $file;
|
||||||
|
}
|
||||||
|
|
||||||
function prettify_textarea($s){
|
function prettify_textarea($s){
|
||||||
return str_replace("\t", '	', str_replace("\n", ' ', htmlentities($s)));
|
return str_replace("\t", '	', str_replace("\n", ' ', htmlentities($s)));
|
||||||
}
|
}
|
||||||
|
|
44
post.php
44
post.php
|
@ -657,6 +657,28 @@ function handle_post(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Convert multiple upload format to array of files. This makes the following code
|
||||||
|
// work the same whether we used the JS or HTML multiple file upload techniques.
|
||||||
|
if (array_key_exists('file_multiple', $_FILES)) {
|
||||||
|
$file_array = $_FILES['file_multiple'];
|
||||||
|
$_FILES = [];
|
||||||
|
// If more than 0 files were uploaded
|
||||||
|
if (!empty($file_array['tmp_name'][0])) {
|
||||||
|
$i = 0;
|
||||||
|
$n = count($file_array['tmp_name']);
|
||||||
|
while ($i < $n) {
|
||||||
|
$_FILES[strval($i+1)] = array(
|
||||||
|
'name' => $file_array['name'][$i],
|
||||||
|
'tmp_name' => $file_array['tmp_name'][$i],
|
||||||
|
'type' => $file_array['type'][$i],
|
||||||
|
'error' => $file_array['error'][$i],
|
||||||
|
'size' => $file_array['size'][$i]
|
||||||
|
);
|
||||||
|
$i++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
$post['name'] = $_POST['name'] != '' ? $_POST['name'] : $config['anonymous'];
|
$post['name'] = $_POST['name'] != '' ? $_POST['name'] : $config['anonymous'];
|
||||||
$post['subject'] = $_POST['subject'];
|
$post['subject'] = $_POST['subject'];
|
||||||
$post['email'] = str_replace(' ', '%20', htmlspecialchars($_POST['email']));
|
$post['email'] = str_replace(' ', '%20', htmlspecialchars($_POST['email']));
|
||||||
|
@ -781,20 +803,14 @@ function handle_post(){
|
||||||
$i = 0;
|
$i = 0;
|
||||||
foreach ($_FILES as $key => $file) {
|
foreach ($_FILES as $key => $file) {
|
||||||
if ($file['size'] && $file['tmp_name']) {
|
if ($file['size'] && $file['tmp_name']) {
|
||||||
$file['filename'] = urldecode($file['name']);
|
if (!in_array($file['error'], array(UPLOAD_ERR_NO_FILE, UPLOAD_ERR_OK))) {
|
||||||
$file['extension'] = strtolower(mb_substr($file['filename'], mb_strrpos($file['filename'], '.') + 1));
|
error(sprintf3($config['error']['phpfileserror'], array(
|
||||||
if (isset($config['filename_func']))
|
'index' => $i+1,
|
||||||
$file['file_id'] = $config['filename_func']($file);
|
'code' => $file['error']
|
||||||
else
|
)));
|
||||||
$file['file_id'] = time() . substr(microtime(), 2, 3);
|
}
|
||||||
|
$post['files'][] = process_filenames($file, $board['dir'], (sizeof($_FILES) > 1), $i);
|
||||||
if (sizeof($_FILES) > 1)
|
$i++;
|
||||||
$file['file_id'] .= "-$i";
|
|
||||||
|
|
||||||
$file['file'] = $board['dir'] . $config['dir']['img'] . $file['file_id'] . '.' . $file['extension'];
|
|
||||||
$file['thumb'] = $board['dir'] . $config['dir']['thumb'] . $file['file_id'] . '.' . ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension']);
|
|
||||||
$post['files'][] = $file;
|
|
||||||
$i++;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -146,10 +146,15 @@
|
||||||
{% trans %}File{% endtrans %}
|
{% trans %}File{% endtrans %}
|
||||||
</th>
|
</th>
|
||||||
<td class="upload-area">
|
<td class="upload-area">
|
||||||
<input type="file" name="file" id="upload_file">
|
<input type="file" name="file_multiple[]" id="upload_file" multiple/>
|
||||||
|
|
||||||
{% if 'js/file-selector.js' in config.additional_javascript %}
|
{% if 'js/file-selector.js' in config.additional_javascript %}
|
||||||
<script type="text/javascript">if (typeof init_file_selector !== 'undefined') init_file_selector({{ config.max_images }});</script>
|
<script type="text/javascript">
|
||||||
|
if (typeof init_file_selector !== 'undefined') {
|
||||||
|
var iOS_ifs = !!navigator.platform && /iPad|iPhone|iPod/.test(navigator.platform);
|
||||||
|
if(!iOS_ifs) { init_file_selector({{ config.max_images }}); }
|
||||||
|
}
|
||||||
|
</script>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue