Added Order Form and File
This commit is contained in:
@@ -2,4 +2,30 @@
|
||||
|
||||
class File extends mfBaseModel {
|
||||
|
||||
|
||||
public function delete() {
|
||||
if($this->id) {
|
||||
$id = $this->id;
|
||||
|
||||
// delete file in store
|
||||
$path = MFUPLOAD_FILE_SAVE_PATH."/documents/".$this->store_filename;
|
||||
if(!unlink($path)) {
|
||||
$this->log->warn(__CLASS__."::delete(): Error unlinking file ($path)");
|
||||
}
|
||||
|
||||
$where = "id=$id";
|
||||
if($this->fieldprefix && !strstr($field,"_")) {
|
||||
$where = $this->fieldprefix."_id=$id";
|
||||
}
|
||||
if($this->db->delete($this->table,$where)) {
|
||||
if(method_exists($this, "afterDelete")) {
|
||||
$this->afterDelete();
|
||||
}
|
||||
$this->data = new stdClass();
|
||||
$this->id = "";
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
}
|
||||
@@ -13,4 +13,60 @@ class FileController extends mfBaseController {
|
||||
$this->redirect("Dashboard");
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
protected function downloadAction() {
|
||||
$id = $this->request->id;
|
||||
if(!is_numeric($id) || $id < 1) {
|
||||
return true;
|
||||
}
|
||||
|
||||
$file = new File($id);
|
||||
if(!$file) {
|
||||
throw new Exception("File not found", 404);
|
||||
}
|
||||
$filename = $file->store_filename;
|
||||
$path = MFUPLOAD_FILE_SAVE_PATH."/documents/$filename";
|
||||
|
||||
//var_dump($path);exit;
|
||||
if(!file_exists($path)) {
|
||||
throw new Exception("File not found", 4041);
|
||||
}
|
||||
|
||||
if(preg_match('/\.([^.]+)/',$filename,$m)) {
|
||||
$ext .= $m[1];
|
||||
} else {
|
||||
throw new Exception("File not found", 4042);
|
||||
}
|
||||
|
||||
$outname = ($file->filename) ? $file->filename : $file->orig_filename;
|
||||
|
||||
if(!$this->sendfile($path, $outname)) {
|
||||
throw new Exception("File not found", 4043);
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
private function sendfile($file,$name) {
|
||||
$this->log->debug("sendfile: $file $name");
|
||||
if (!$fh = fopen($file, 'r')) {
|
||||
return false;
|
||||
}
|
||||
|
||||
set_time_limit(36000);
|
||||
header('Content-Type: application/octet-stream');
|
||||
header('Content-disposition: attachment; filename="' . $name . '"');
|
||||
|
||||
$size = exec('stat -c %s '.escapeshellarg($file));
|
||||
if($size < (pow(2,31))-1) {
|
||||
header('Content-Length: ' . $size);
|
||||
}
|
||||
|
||||
while (!feof($fh)) {
|
||||
$data = fread($fh, 8192);
|
||||
echo $data;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -4,6 +4,7 @@ class FileModel {
|
||||
public $name;
|
||||
public $description;
|
||||
public $filename;
|
||||
public $store_filename;
|
||||
public $orig_filename;
|
||||
public $subfolder;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user