wmdeit_kaform/upload.php

92 lines
2.1 KiB
PHP

<?php
session_start();
#error_log("Here is upload.php");
file_put_contents("/tmp/log.txt", "uploadder\n", FILE_APPEND | LOCK_EX);
function xvar_dump ($x) {
ob_start();
var_dump($x);
return ob_get_clean();
}
$jo = array();
foreach ($_FILES as $key=>$files){
for ($i=0; $i < count($files['name']); $i++){
$tmpname = $files['tmp_name'][$i];
$ft = mime_content_type($tmpname);
file_put_contents("/tmp/log.txt", "MIME: $ft\n", FILE_APPEND | LOCK_EX);
if ($ft == "application/pdf"){
$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);
$_SESSION['files'][$tmpname]['content']=file_get_contents($tmpname);
$_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 = "$CONVERT_CMD $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;
}
}
}
$files = "";
foreach ($_SESSION['files'] as $key => $val) {
$files .= "$key\n";
}
$j = json_encode ($jo);
echo $j;
file_put_contents("/tmp/log.txt", $j, FILE_APPEND | LOCK_EX);
#error_log("\n\n ----- files ----- \n\n$files\n\n\n");
#$xp = xvar_dump($_FILES);
#error_log("\n\n ----- FILES ----- \n\n$$xp\n\n\n");