1
0
Fork 0

Accepts and converts Jpegs

This commit is contained in:
Tobias Herre 2021-11-23 13:44:08 +01:00
parent 147de59bac
commit db5991c0de
1 changed files with 32 additions and 5 deletions

View File

@ -19,12 +19,10 @@ foreach ($_FILES as $key=>$files){
$tmpname = $files['tmp_name'][$i]; $tmpname = $files['tmp_name'][$i];
$ft = mime_content_type($tmpname); $ft = mime_content_type($tmpname);
if ($ft != "application/pdf"){
$jo = array(
"type" => "error"
);
} else { file_put_contents("/tmp/log.txt", "MIME: $ft\n", FILE_APPEND | LOCK_EX);
if ($ft == "application/pdf"){
$jo ["file-$key-$i"] = array( $jo ["file-$key-$i"] = array(
"url" => "url.txt", "url" => "url.txt",
@ -39,6 +37,35 @@ foreach ($_FILES as $key=>$files){
$_SESSION['files'][$tmpname]['content']=file_get_contents($tmpname); $_SESSION['files'][$tmpname]['content']=file_get_contents($tmpname);
$_SESSION['files'][$tmpname]['row']=$_GET['row']; $_SESSION['files'][$tmpname]['row']=$_GET['row'];
}else if ($ft == "image/jpeg") {
$jo ["file-$key-$i"] = array(
"url" => "url.txt",
"name" => $files['name'][$i],
"id" => $tmpname,
"size" => sprintf("%0.1fK",$files['size'][$i]/1024.0)
);
file_put_contents("/tmp/log.txt", "file-$key-$i\n", FILE_APPEND | LOCK_EX);
file_put_contents("/tmp/log.txt", $files['name'][$i], FILE_APPEND | LOCK_EX);
$tmpfname = tempnam("/tmp", "FOO");
$cmd = "/usr/local/bin/convert $tmpname PDF:$tmpfname";
exec ($cmd);
file_put_contents("/tmp/log.txt", "\n$cmd\n");
$_SESSION['files'][$tmpname]['content']=file_get_contents($tmpfname);
$_SESSION['files'][$tmpname]['row']=$_GET['row'];
unlink ($tmpfname);
}
else {
file_put_contents("/tmp/log.txt", "ERRORZWEIK\n", FILE_APPEND | LOCK_EX);
$jo = array(
"type" => "error"
);
$j = json_encode ($jo);
echo $j;
return;
} }