|
Posted by Steve on 11/29/06 04:30
"Dirk van Lierop" <d.vanlierop1@chello.nl> wrote in message
news:65cb1$456cb18d$d55d7ad6$10635@news.chello.nl...
| Hi all,
|
| I have searched all the web for a php script to store and view receipts.
| Something with a search function would be nice. If there is a possibility
to
| store pictures with the receipts its nice but not nessacery.
|
| If someone knows where i can find such a script, please let me know
|
| Thanks in advance.
|
| Dirk van Lierop
alright...i know, i know...don't feed the bears! lol. here's a basic upload
script. you'll need to edit appropriately as i have classes involved that
handle directory locations, constants, etc.. the main portion of the code
will work without much editing however. i'll post the script to show the
uploaded doc's as a thumbnail and that allow you to open them in the
browser.
<?
$pageTitle = isset($pageTitle) ? $pageTitle : "Upload File";
$parsedUri = dirname($_SERVER['PHP_SELF']);
$relativeUri = str_replace('/', '', $parsedUri);
$nestLevel = strlen($parsedUri) - strlen($relativeUri);
$securityEnabled = true;
if ($nestLevel < 0){ $nestLevel = 0; }
require_once str_repeat('../', $nestLevel) . 'inc/head.inc.php';
require_once $site->includeDirectory . 'functions.inc.php';
define("UPLOAD_ERR_DEST_EXISTS", 5);
$add = isset($_REQUEST['add']);
$back = isset($_REQUEST['back']);
$delete = isset($_REQUEST['delete']);
$edit = isset($_REQUEST['edit']);
$fileProperties = $_FILES['fileProperties'];
$fileDescription = $_REQUEST['fileDescription'];
$createOrUpdate = $_REQUEST['createOrUpdate'];
$id = isset($_REQUEST['id']) ? $_REQUEST['id'] : 0;
$method = isset($_REQUEST['method']) ? $_REQUEST['method'] : '';
?>
<div class="pageIntro" style="padding-bottom:35px;">
<span class="dropCap" style="color:#F2E8BB;">U</span><b>pload Files</b>
</div>
<br>
<hr>
<br>
<br>
<?
if ($back)
{
$add = false;
$delete = false;
$edit = false;
$method = '';
}
if ($delete)
{
$add = false;
$delete = false;
$edit = false;
$method = '';
$sql = "
SELECT FileName
FROM upLoads
WHERE Id = '" . $id . "'
";
$records = $db->execute($sql);
@unlink($records[0]['FILENAME']);
$sql = "
DELETE
FROM upLoads
WHERE Id = '" . $id . "'
";
$db->execute($sql);
}
if ($add || $edit)
{
$action = $add ? 'add' : 'edit';
$sql = "
SELECT COUNT(*) UploadExists
FROM upLoads
WHERE Id = '" . $id . "'
OR UPPER(FileName) = UPPER('" .
$db->prepare($fileProperties['name']) . "')
";
$records = $db->execute($sql);
$uploadExists = $records[0]['UPLOADEXISTS'] > 0;
if ($fileProperties && $fileProperties['error'] == UPLOAD_ERR_OK)
{
$temporaryFile = $fileProperties['tmp_name'];
$filePath = $site->uploadBaseDirectory ;
$storedFile = $filePath . $fileProperties['name'];
if (!is_dir($filePath)){ mkdir($filePath); }
if ($createOrUpdate)
{
if ($createOrUpdate && file_exists($storedFile)){
unlink($storedFile); }
move_uploaded_file($temporaryFile, $storedFile);
}
if (!$createOrUpdate && file_exists($storedFile)){
$fileProperties['error'] = UPLOAD_ERR_DEST_EXISTS; }
@unlink($temporaryFile);
if (!$uploadExists)
{
$sql = "
INSERT INTO upLoads
(
Description ,
FileName ,
FileSize ,
FileType
)
VALUES
(
'" . $db->prepare($fileDescription) . "' ,
'" . $db->prepare($fileProperties['name']) . "' ,
'" . $db->prepare($fileProperties['size']) . "' ,
'" . $db->prepare($fileProperties['type']) . "'
)
";
unset($records);
$records = $db->execute($sql, true);
$id = $records[0]['ID'];
}
if ($uploadExists)
{
$sql = "
UPDATE upLoads
SET Description = '" . $db->prepare($fileDescription)
.. "' ,
FileName = '" .
$db->prepare($fileProperties['name']) . "' ,
FileSize = '" .
$db->prepare($fileProperties['size']) . "' ,
FileType = '" .
$db->prepare($fileProperties['type']) . "'
WHERE Id = '" . $id
.. "'
";
if ($createOrUpdate){
}
if (!$createOrUpdate){ $fileProperties['error'] =
UPLOAD_ERR_DEST_EXISTS; }
}
}
if (isset($fileProperties) && $fileProperties['error'] != UPLOAD_ERR_OK)
{
switch ($fileProperties['error'])
{
case UPLOAD_ERR_INI_SIZE :
case UPLOAD_ERR_FORM_SIZE :
$fileProperties['error'] = '<big><b>FILE IS TOO
LARGE</b></big><br><br>
The file being uploaded is larger
than this site allows.';
break;
case UPLOAD_ERR_PARTIAL :
$fileProperties['error'] = '<big><b>FILE UPLOAD
ERROR</b></big><br><br>
The file was only partially
uploaded.';
break;
case UPLOAD_ERR_DEST_EXISTS :
$fileProperties['error'] = '<big><b>FILE
EXISTS</b></big><br><br>
Either rename the file or select
"Create Or Update".';
break;
case UPLOAD_ERR_NO_FILE :
$fileProperties['error'] = '<big><b>FILE NOT
SELECTED</b></big><br><br>
Either type the path and name of the
file you wish to upload,<br>
or use the "Browse ..." button to
navigate to the file.';
break;
}
?>
<div>
<?= $fileProperties['error'] ?>
<br>
<br>
<big><b>Please try again.</b></big>
<br>
<br>
<hr>
</div>
<br>
<br>
<?
}
?>
<script language="javascript">
var skipValidation = false;
function validate()
{
if (skipValidation){ return true; }
var warning = new String();
var el;
if (trim(upload.fileDescription.value) == "")
{
warning += "Description is required.";
if (!el){ el = upload.fileDescription; }
}
if (warning.length)
{
alert(warning);
el.focus()
el.select();
return false;
}
return true;
}
</script>
<?
$sql = "
SELECT Id
,
Description
,
FileName
,
FileSize
,
FileType
,
DATE_FORMAT(Stamp, '%m/%d/%Y %H:%i:%s') Stamp
FROM upLoads
WHERE Id = '" . $db->prepare($id) . "'
";
unset($records);
$records = $db->execute($sql);
$fileProperties['id'] = $records[0]['ID'];
$fileProperties['description'] = $records[0]['DESCRIPTION'];
$fileDescription = $records[0]['DESCRIPTION'];
$fileProperties['name'] = $records[0]['FILENAME'];
$fileProperties['size'] = formatBytes($records[0]['FILESIZE']);
$fileProperties['type'] = $records[0]['FILETYPE'];
$fileProperties['uploadDate'] = $records[0]['STAMP'];
$queryString = "?fileName=" .
urlencode($fileProperties['name']) . "&maxSize=200";
?>
<form name="upload" method="post" enctype="multipart/form-data"
onsubmit="return validate();">
<table>
<tr>
<td style="width:150px;"><span class="label">Description</span></td>
<td>
<input autocomplete="off" class="value" name="fileDescription"
type="text" value="<?= $fileDescription ?>">
</td>
</tr>
<tr>
<td style="width:150px;"><span class="label">File To
Upload</span></td>
<td>
<input class="value" name="fileProperties" type="file" "<?=
$readOnly ?>">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000">
</td>
</tr>
<tr>
<td style="width:150px;"><span class="label">Create Or
Update</span></td>
<td>
<input class="value" name="createOrUpdate" style="border-width:'0px';
text-align:'left';" type="checkbox" checked>
</td>
</tr>
</table>
<br>
<hr>
<br>
<input name="<?= $action ?>" type="submit" style="cursor:'hand';
width:100px;" value="Save ▷">
<input name="delete" type="submit" style="cursor:'hand';
width:100px;" value="Delete ▷" onclick="return
confirmDelete();">
<input name="back" type="submit" style="cursor:'hand';
width:100px;" value="Back ▷"
onclick="skipValidation=true;">
<input name="id" type="hidden" value="<?= $id ?>">
<input name="method" type="hidden" value="put">
</form>
<?
echo $sessionFooter;
exit;
}
?>
<a class="menuItem" href="Add" style="color:#990000;" onclick="return
add();">▷ Add new file ...</a>
<br>
<br>
<div id="action">
</div>
<script language="javascript">
function add()
{
var form = '';
form += "<form method='post' name='records'>\r\n";
form += " <input type='hidden' name='add' value='1'>\r\n";
form += " <input type='hidden' name='method' value='get'>\r\n";
form += "</form>\r\n";
document.getElementById("action").innerHTML = form;
document.records.submit();
return false;
}
function edit(id)
{
var form = '';
form += "<form method='post' name='records'>\r\n";
form += " <input type='hidden' name='id' value='" + id +
"'>\r\n";
form += " <input type='hidden' name='edit' value='1'>\r\n";
form += " <input type='hidden' name='method' value='get'>\r\n";
form += "</form>\r\n";
document.getElementById("action").innerHTML = form;
document.records.submit();
return false;
}
</script>
<?
$sql = "
SELECT Id
,
Description
,
FileName
,
FileSize
,
FileType
,
DATE_FORMAT(Stamp, '%m/%d/%Y %H:%i:%s') Stamp
FROM upLoads
ORDER BY FileName
";
$records = $db->execute($sql);
foreach ($records as $row => $record)
{
$queryString = "?fileName=" . $record['FILENAME'] . "&maxSize=200";
?>
<table style="width:100%;">
<tr>
<td class="label" style="text-align:left; vertical-align:middle;
width:300px;">
<a
class="menuItem"
href="Edit"
title="Click To Edit: <?= $record['DESCRIPTION'] ?>"
onclick="return edit('<?= $record['ID'] ?>');"
>▷ Edit <?= $record['DESCRIPTION'] ?></a>
</td>
<td class="value" style="text-align:left; width:200px;">
<a
href="<?= $site->uri ?>get.file.php<?= $queryString ?>"
style="font-size:12pt;"
>
<img
src="<?= $site->uri ?>get.thumb.nail.php<?= $queryString ?>"
alt="<?= $record['DESCRIPTION'] ?>"
title="Click To Open: <?= $record['DESCRIPTION'] ?>"
/>
</a>
</td>
</tr>
<tr>
<td class="label" style="text-align:right; width:200px;">
File Name
</td>
<td class="value" style="text-align:left; width:200px;">
<?= $record['FILENAME'] ?>
</td>
</tr>
<tr>
<td class="label" style="text-align:right; width:200px;">
File Size
</td>
<td class="value" style="text-align:left; width:200px;">
<?= formatBytes($record['FILESIZE']) ?>
</td>
</tr>
<tr>
<td class="label" style="text-align:right; width:200px;">
File Type
</td>
<td class="value" style="text-align:left; width:200px;">
<?= $record['FILETYPE'] ?>
</td>
</tr>
<tr>
<td class="label" style="text-align:right; width:200px;">
Uploaded
</td>
<td class="value" style="text-align:left; width:200px;">
<?= $record['STAMP'] ?>
</td>
</tr>
</table>
<br>
<br>
<?
}
echo $sessionFooter;
?>
Navigation:
[Reply to this message]
|