Pk11 3 years ago committed by GitHub
parent 98d3dc6c4c
commit f94426ed7d

@ -35,6 +35,7 @@
* *
* // Application constants * // Application constants
* define('UPLOAD_PATH', 'image/'); // Folder to save images to * define('UPLOAD_PATH', 'image/'); // Folder to save images to
* define('THUMB_PATH', 'thumb/'); // Folder to save thumbnails to
* define('MAX_FILE_SIZE', 8 << 20); // Maximum image size, 8 MiB * define('MAX_FILE_SIZE', 8 << 20); // Maximum image size, 8 MiB
* define('ADMIN_ID', '<SHA1 uid from your cookies>'); // uid that is able to delete anything * define('ADMIN_ID', '<SHA1 uid from your cookies>'); // uid that is able to delete anything
* define('UID_SALT', '<some string to salt uids with>'); * define('UID_SALT', '<some string to salt uids with>');
@ -79,8 +80,18 @@
&& ($img['size'] > 0) && ($img['size'] <= MAX_FILE_SIZE)) { && ($img['size'] > 0) && ($img['size'] <= MAX_FILE_SIZE)) {
if($img['error'] == 0) { if($img['error'] == 0) {
// Move the file to the target upload folder // Move the file to the target upload folder
$target = UPLOAD_PATH . time() . $extensions[$img['type']]; $name = time();
if(!move_uploaded_file($img['tmp_name'], $target)) { $target = UPLOAD_PATH . $name . $extensions[$img['type']];
if(move_uploaded_file($img['tmp_name'], $target)) {
$output = null;
$ret = null;
exec("ffmpeg -y -loglevel error -i '$target' -vf 'scale=-1:min(100\,ih)' " . THUMB_PATH . "$name.jpg", $output, $ret);
if($ret != 0) {
// The new image file move failed, so delete the temporary file and return an error
@unlink($target);
return 'Unable to create thumbnail, please contact the webmaster.';
}
} else {
// The new image file move failed, so delete the temporary file and return an error // The new image file move failed, so delete the temporary file and return an error
@unlink($img['tmp_name']); @unlink($img['tmp_name']);
return 'Unable to upload image, please contact the webmaster.'; return 'Unable to upload image, please contact the webmaster.';
@ -171,7 +182,7 @@
if(!empty($row['img'])){ if(!empty($row['img'])){
echo '<a href="' . UPLOAD_PATH . $row['img'] . '" target="_blank">'; echo '<a href="' . UPLOAD_PATH . $row['img'] . '" target="_blank">';
echo '<img src="' . UPLOAD_PATH . $row['img'] . '" alt="' . $row['img'] . '" />'; echo '<img src="' . THUMB_PATH . preg_replace('/\.(?:png|gif|bmp)$/', '.jpg', $row['img']) . '" alt="' . $row['img'] . '" />';
echo '</a>'; echo '</a>';
} }
@ -327,4 +338,4 @@
</a> </a>
</p> </p>
</body> </body>
</html> </html>

Loading…
Cancel
Save