Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Cancel an HTTP POST request server side

Tags:

http

post

php

perl

I am trying to write a script for uploading large files (>500MB). I would like to do some authentication before the upload is processed, eg:

$id = $_GET['key'];
$size = $_GET['size'];
$time = $_GET['time'];
$signature = $_GET['signature'];

$secret = 'asdfgh123456';

if(sha1($id.$size.$time.$secret) != $signature){
echo 'invalid signature';
exit;
}
process upload...

unfortunately php only runs this code after the file has been uploaded to a temp directory, taking up valuable server resources. Is there a way to do this before the upload happens? I have tried similar things with perl/cgi but the same thing happens.

like image 632
Jack000 Avatar asked Jul 12 '26 05:07

Jack000


2 Answers

Wow, already 5 answers telling how it can't be done. mod_perl to the rescue, here you can reject a request before the whole request body is uploaded.

like image 72
daxim Avatar answered Jul 14 '26 18:07

daxim


Apache is taking care of the upload before the PHP script is even invoked so you won't be able to get at it.

You can either split up the process into two pages (authentication, file upload page) or, if you need to do it all in one page, use an AJAX-esque solution to upload the file after authentication parameters are checked.

like image 26
webbiedave Avatar answered Jul 14 '26 18:07

webbiedave



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!