Skip to content

Instantly share code, notes, and snippets.

@emasters
Last active February 23, 2016 15:06
Show Gist options
  • Select an option

  • Save emasters/34c9b5b1ced28ab2ec4e to your computer and use it in GitHub Desktop.

Select an option

Save emasters/34c9b5b1ced28ab2ec4e to your computer and use it in GitHub Desktop.
Minimal A2J GI uploading
<?php
/**
* 2/22/2016 ERM
* every upload has a Guide.xml file. Let's display it.
**/
header('Content-type: text/xml');
chdir($_GET['UploadDir']);
$xml = simplexml_load_file('Guide.xml');
echo $xml->asXML();
?>
<?php
/**
* 7/2008 SJG Handle upload of a single file
* 08/10/2015 Mimic LHI's A2J 5 file upload handler.
* 02/22/2016 ERM tweaked it a bit to save and unzip the upload
**/
logmsg("-----------");
$UploadFolder = "uploads/";
header("Content-Type: text/plain");
session_start();
$PHPSESSID=session_id();
logmsg(var_export( $_SERVER,true));
logmsg(var_export( $_REQUEST,true));
logmsg(var_export( $_SESSION,true));
logmsg(var_export( $_COOKIE,true));
logmsg(var_export( $_FILES,true));
if (($tempName=$_FILES['file']['tmp_name'])!="")
{
logmsg("tempName=$tempName");
$name= str_replace(" ","_",$_FILES['file']['name']);
logmsg("name=$name");
// create a folder to stash the zip into
$dirname = $PHPSESSID;
mkdir($UploadFolder.$dirname,0777);
// move the zip to the new folder
move_uploaded_file($tempName,$UploadFolder.$dirname.'/'.$name);
// unzip the file
$zipfile = $UploadFolder.$dirname.'/'.$name;
// get the absolute path to $file
$path = pathinfo(realpath($zipfile), PATHINFO_DIRNAME);
$zip = new ZipArchive;
$res = $zip->open($zipfile);
if ($res === TRUE) {
// extract it to the path we determined above
$zip->extractTo($path);
$zip->close();
$strURL = "http://a2j.freelawreporter.org/A2JFileInfo.php?UploadDir=$path&UploadedFile=$name";
} else {
$strURL = "http://a2j.freelawreporter.org/A2JFileInfo.php?UploadedFile=it_didnt_work";
}
}
function logmsg($msg)
{
$handle = fopen ("A2JFilePut.log", "a");
fwrite($handle,$msg."\n");
fclose($handle);
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1"><title>
A2J Loader
</title></head>
<body>
<strURL><?=$strURL?></strURL>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment