Is there a simple upload status bar in any language that would work with a HTML form. The form is submitted to put info into a database with user and project info so the form part is very necessary. I'm beating my head against the wall on this one. Not sure how much code you all would like to see but here is the form submit part as in the original file.
Code: Select all
<?php
/**
* @author 23rd and Walnut
* @copyright 2010
*/
?>
<div id="form-top"></div>
<div id="form">
<div class="error_list">
<?php
if (isset($error_list))
echo $error_list;
?>
</div>
<form id="new_file" enctype="multipart/form-data" action="index.php?a=documents/add/<?php echo $project?>" method="post">
<div><h2 class="form-title">Upload Document</h2></div>
<div>
<label>Document Description</label>
<input type="text" name="document_name" id="document_name" class="wide" />
</div>
<div>
<label>Project Phase</label>
<select name="phase" id="phase" class="wide">
<option value=""></option>
<?php $n=1; ?>
<?php foreach($phases as $phase)
{
echo "<option value='".$n++."'>".$phase."</option>";
}
?>
</select>
</div>
<div>
<input type="hidden" name="MAX_FILE_SIZE" value="2000000" />
<label>File to upload </label>
<input name="document" type="file" />
</div>
<div class="clearfix">
<input type="image" id="submit" name="submit" alt="Submit" src="application/views/images/button-login.png" value="submit"/>
</div>
</form>
<div id="form-bottom"></div>
Code: Select all
<?php
/**
* @author 23rd and Walnut
* @copyright 2010
*/
class DocumentsController extends Controller
{
/**
* Add a new document for a project
*/
function add($project)
{
$this->loadLibrary('formvalidator.class');
if($user = $this->logged_in())
{
global $allow_client_uploads;
if($user['group_id']==0 || $allow_client_uploads == true)
{
$this->loadModel('Project');
$project_details = $this->Project->details($project);
/**
* Make sure client has access to this project
*/
if($user['group_id'] != 0 )
{
if($user['id'] != $project_details['client_id'])
{
return false;
}
}
/**
* Gets a list of project phases for the
* new document form
*/
$phases = $this->Project->get_phases($project);
$this->set('phases', $phases);
$this->set('project', $project);
/**
* Display form with no errors if
*/
if(!isset($_POST['document_name']) && !isset($_FILES['document']))
{
$this->loadView('new-file');
}
else
{
$document_name = $_POST['document_name'];
$document = $_FILES['document']['name'];
$phase = $_POST['phase'];
/**
* Validate user inputs
*/
$validator = new FormValidator();
$project_name = $validator->run($document_name, 'Document Description', 'required|clean');
$document = $validator->run($document, 'Document', 'required|clean');
$document = $validator->run($phase, 'Phase', 'required|clean');
if ($validator->has_errors == true)
{
$this->loadView('new-file');
}
else
{
$rel_project = $this->Project->details($project);
$rel_client_id = $rel_project['client_id'];
$this->loadModel('Client');
$uploaded_by = $this->Client->get_client_details($user['id']);
$this->loadModel('Document');
/**
* Add the document to the project
*/
if($this->Document->add_document($rel_client_id, $document_name, $project, $phase, $uploaded_by))
{
$this->alert("Document Uploaded Successfully", "success");
$this->redirect('projects/view/'.$project);
}
else
{
$this->alert("There was an error uploading the file", "error");
$this->redirect('projects/view/'.$project);
}
}
}
}
else $this->redirect('portal/home');
}
else
{;}
}
/**
* Initiate download of the requested
* document
*/
function download($document)
{
/** Check that the user is logged in **/
if($user = $this->logged_in())
{
/** Make sure the document is associated
* with the user account or the user is an
* admin
*/
$this->loadModel('Document');
if (!$this->Document->authorized_to_download($document, $user))
{
return false;
}
/** Turn off error reporting to avoid
* document getting corrupted
*/
error_reporting(0);
/**
* Verify file exists then send to
* browser
*/
global $document_upload_path;
$document = $document_upload_path.$document;
if (file_exists($document))
{
header('Content-Description: File Transfer');
header('Content-Type: application/octet-stream');
header('Content-Disposition: attachment; filename='.basename($document));
header('Content-Transfer-Encoding: binary');
header('Expires: 0');
header('Cache-Control: must-revalidate, post-check=0, pre-check=0');
header('Pragma: public');
header('Content-Length: ' . filesize($document));
ob_clean();
flush();
readfile($document);
exit;
}
else
{
$this->alert("The requested file does not exist", "error");
$this->redirect("portal/home");
}
}
}
function delete($path, $description)
{
$auth = false;
if($user = $this->logged_in())
{
if($user['group_id']==0)
{
$auth = true;
}
}
if($auth == true)
{
$this->loadModel("Document");
$this->Document->delete($path, $description);
$this->alert("Document Deleted", "notice");
$this->redirect("portal/home");
}
}
}
?>Thanks!