Browse Source

Fix rejected images not being deleted

$file['thumb_path'] and $file['thumb_path'] need to be set before calling undoImage($file).
main
Couchy 5 years ago
committed by discomrade
parent
commit
2a1d99a4bb
  1. 4
      inc/functions.php
  2. 42
      post.php

4
inc/functions.php

@ -3319,8 +3319,8 @@ function process_filenames($file, $board_dir, $multiple, $i){
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']);
$file['file_path'] = $board_dir . $config['dir']['img'] . $file['file_id'] . '.' . $file['extension'];
$file['thumb_path'] = $board_dir . $config['dir']['thumb'] . $file['file_id'] . '.' . ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension']);
return $file;
}

42
post.php

@ -562,7 +562,7 @@ if (isset($_POST['delete'])) {
else if (!in_array($post['extension'], $config['allowed_ext']) && !in_array($post['extension'], $config['allowed_ext_files']))
error($config['error']['unknownext']);
$post['file_tmp'] = tempnam($config['tmp'], 'url');
$post['file_tmp'] = @tempnam($config['tmp'], 'url');
register_shutdown_function('unlink_tmp_file', $post['file_tmp']);
$fp = fopen($post['file_tmp'], 'w');
@ -994,7 +994,7 @@ if (isset($_POST['delete'])) {
$file['extension'] == ($config['thumb_ext'] ? $config['thumb_ext'] : $file['extension'])) {
// Copy, because there's nothing to resize
copy($file['tmp_name'], $file['thumb']);
copy($file['tmp_name'], $file['thumb_path']);
$file['thumbwidth'] = $image->size->width;
$file['thumbheight'] = $image->size->height;
@ -1005,7 +1005,7 @@ if (isset($_POST['delete'])) {
$post['op'] ? $config['thumb_op_height'] : $config['thumb_height']
);
$thumb->to($file['thumb']);
$thumb->to($file['thumb_path']);
$file['thumbwidth'] = $thumb->width;
$file['thumbheight'] = $thumb->height;
@ -1019,7 +1019,7 @@ if (isset($_POST['delete'])) {
escapeshellarg($file['tmp_name'])))
error(_('Could not strip EXIF metadata!'), null, $error);
} else {
$image->to($file['file']);
$image->to($file['file_path']);
$dont_copy_file = true;
}
}
@ -1044,7 +1044,6 @@ if (isset($_POST['delete'])) {
}
else {
// not an image
//copy($config['file_thumb'], $post['thumb']);
$file['thumb'] = 'file';
$size = @getimagesize(sprintf($config['file_thumb'],
@ -1055,21 +1054,22 @@ if (isset($_POST['delete'])) {
}
}
if ($config['tesseract_ocr'] && $file['thumb'] != 'file') { // Let's OCR it!
$fname = $file['tmp_name'];
if ($config['tesseract_ocr'] && $file['is_an_image']) { // Let's OCR it!
$fname = '';
if ($file['height'] > 500 || $file['width'] > 500) {
$fname = $file['thumb'];
if ($file['thumb'] != 'spoiler') {
$fname = $file['thumb_path'];
}
}
else
$fname = $file['tmp_name'];
if ($fname == 'spoiler') { // We don't have that much CPU time, do we?
}
else {
$tmpname = __DIR__ . "/tmp/tesseract/".rand(0,10000000);
if ($fname != '') {
$tmpname = "tmp/tesseract/".rand(0,10000000);
// Preprocess command is an ImageMagick b/w quantization
$error = shell_exec_error(sprintf($config['tesseract_preprocess_command'], escapeshellarg($fname)) . " | " .
'tesseract stdin '.escapeshellarg($tmpname).' '.$config['tesseract_params']);
'tesseract stdin '.escapeshellarg($tmpname).' '.$config['tesseract_params']);
$tmpname .= ".txt";
$value = @file_get_contents($tmpname);
@ -1085,10 +1085,10 @@ if (isset($_POST['delete'])) {
if (!isset($dont_copy_file) || !$dont_copy_file) {
if (isset($file['file_tmp'])) {
if (!@rename($file['tmp_name'], $file['file']))
if (!@rename($file['tmp_name'], $file['file_path']))
error($config['error']['nomove']);
chmod($file['file'], 0644);
} elseif (!@move_uploaded_file($file['tmp_name'], $file['file']))
chmod($file['file_path'], 0644);
} elseif (!@move_uploaded_file($file['tmp_name'], $file['file_path']))
error($config['error']['nomove']);
}
}
@ -1171,11 +1171,9 @@ if (isset($_POST['delete'])) {
// Remove board directories before inserting them into the database.
if ($post['has_file']) {
foreach ($post['files'] as $key => &$file) {
$file['file_path'] = $file['file'];
$file['thumb_path'] = $file['thumb'];
$file['file'] = mb_substr($file['file'], mb_strlen($board['dir'] . $config['dir']['img']));
if ($file['is_an_image'] && $file['thumb'] != 'spoiler')
$file['thumb'] = mb_substr($file['thumb'], mb_strlen($board['dir'] . $config['dir']['thumb']));
$file['file'] = mb_substr($file['file_path'], mb_strlen($board['dir'] . $config['dir']['img']));
if (!isset($file['thumb']))
$file['thumb'] = mb_substr($file['thumb_path'], mb_strlen($board['dir'] . $config['dir']['thumb']));
}
}

Loading…
Cancel
Save