Rev 59 | Rev 63 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed
<?php
include_once( '../../header.php' );
include_once( './functions.php' );
$result = '';
$debug = '';
if ( isset( $_REQUEST['uploadfile'] ) ) {
// clean up the input first
$client_id = cleanInput( $_REQUEST['client_id'] );
$site_id = cleanInput( $_REQUEST['site_id'] );
$device_id = cleanInput( $_REQUEST['device_id'] );
$name = cleanInput( $_REQUEST['name'], $_FILES['fileToUpload']['name'] );
$description = cleanInput( $_REQUEST['description'] );
$mime_type_id = $_REQUEST['mime_type'];
// mime_type_id can be passed in, calculated from the 'type' of $_FILES, or looked up by extension
if ( $mime_type_id == 0 ) { // we need to calculate the mime type (auto mode)
// see if $_FILES has the info
$mime_type_id = check_mime_type( $_FILES['fileToUpload']['type'] );
if ( $mime_type_id === null ) { // no, so see if we can figure it out from the file name
$mime_type_id = check_mime_type( pathinfo($_FILES['fileToUpload']['name'], PATHINFO_EXTENSION) );
}
}
$debug = "client_id =[$client_id]<br />
site_id =[$site_id]<br />
device_id =[$device_id]<br />
name =[$name]<br />
mime_type_id=[$mime_type_id]<br />
description =[$description]<br />";
/*
* this documentation will use the following example
* A file, joe.csv, is uploaded and attached to the client
* Walder IP Law. makeFileName discovers it to be file number
* 123456 (based on an internal counter)
* All comments below show what is returned
*/
$result = makeFileName(
$_FILES['fileToUpload']['name'],
$device_id,
$client_id,
$site_id
);
// at this point, we have 12/34/123456-c-Walder IP Law.csv
if ( $result['valid'] ) {
$nameOnDisk = $result['filename'];
$saveTo = getAbsolutePath( $nameOnDisk );
// $saveT now has document root, etc... prepended, so
// /var/www/computer_asset_management/modules/files/file_storage/12/34/123456-c-Walder IP Law.csv
if ( makePath( $saveTo ) ) {
$result = "Path Made - $saveTo";
if ( ( move_uploaded_file( $_FILES["fileToUpload"]["tmp_name"], $saveTo ) ) ) {
$result = addfile(
$nameOnDisk,
$device_id,
$client_id,
$site_id,
isset( $_REQUEST['mime_type'] ) ? $_REQUEST['mime_type'] : $_FILES["fileToUpload"]['type'],
$name,
$description
);
$result = $result === null ? "Could not add file<br />$nameOnDisk<br />to database" : 'Success';
} else {
$result = "Failed to upload to disk<br />$saveTo";
} // if move_uploaded_file .. else
} else {
$result = "failed to make path<br />$saveTo";
}
} else {
$result = $result['message'];
} // if nameOnDisk .. else
} // if isset uploadfile
?>
<?xml version="1.0" encoding="utf-8"?>
<!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>
<title>Daily Data - Computer Asset Management Program</title>
<link rel="stylesheet" type="text/css" href="../../camp.css">
</head>
<body>
<?php include_once('../../menu.php'); ?>
<div id="content">
<?php
if ( isset( $result ) ) print "<h3>$result</h3>";
//if ( isset( $debug ) ) print "<h3>$debug</h3>";
?>
<p>Choose only <b>one</b> of device, site or client to add the file to</p>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<table>
<tr>
<td>
Attach To Device
</td>
<td>
<select name='device_id' >
<option value='0'>------------</option>
<?php print queryToSelect('select device_id, Device from view_current_client_systems order by Device' ); ?>
</select>
</td>
</tr>
<tr>
<td>
Attach To Site
</td>
<td>
<select name='site_id' >
<option value='0'>------------</option>
<?php print queryToSelect('select site_id, name from view_current_client_site order by name' ); ?>
</select>
</td>
</tr>
<tr>
<td>
Attach To Client
</td>
<td>
<select name='client_id' >
<option value='0'>------------</option>
<?php print queryToSelect('select client_id, name from view_current_client order by name' ); ?>
</select>
</td>
</tr>
<tr>
<td>
Mime Type
</td>
<td>
<select name='mime_type_id' >
<option value='0'>Autodetect</option>
<?php print queryToSelect("select file_mime_type_id, concat( extension, ' (', mime_type, ')') from file_mime_type order by extension" ); ?>
</select>
</td>
</tr>
<tr>
<td>
file Name
</td>
<td>
<input type="text" name="name" size="30" maxlength="64" />
</td>
</tr>
<tr>
<td valign='top'>
Description
</td>
<td>
<textarea name="description" cols='50' rows='5'></textarea>
</td>
</tr>
<tr>
<td>
Choose File
</td>
<td>
<input name="fileToUpload" type="file" />
</td>
</tr>
<tr>
<td colspan='2' align="center">
<input type="submit" name="uploadfile" value="Upload" />
</td>
</tr>
</table>
</form>
</div>
</body>
</html>