public function uploadFile($file) { $target_dir = "data/"; $filename = md5(time()); $i = 1; $cpt = md5($i); $ext = strtolower(substr(strrchr($file['name'], '.'), 1)); $target_file = $target_dir . $filename . "_" . $cpt . "." . $ext; // Si le fichier existe while (file_exists(Page::path($target_file))) { $i++; $cpt = md5($i); $target_file = $target_dir . $filename . "_" . $cpt . "." . $ext; } if (move_uploaded_file($file["tmp_name"], $target_file)) { $f = new FileObject(); $f->permission = "access content"; $f->module = ""; $f->path = "/" . $target_file; $f->content_type = $file['type']; $f->save(); return $f->id_file; } else { return false; } }
public static function page_download_content($id_file) { $theme = new Theme(); $f = new FileObject(); if ($f->load($id_file)) { $f->nb_dl++; $f->save(); $filename = Page::path($f->path); if (ini_get('zlib.output_compression')) { ini_set('zlib.output_compression', 'Off'); } header('Pragma: public'); // required header("Content-Type: {$f->content_type}"); header('Content-Disposition: attachment; filename="' . $f->id_file . '.' . $f->getExtension() . '"'); header('Content-Transfer-Encoding: binary'); header('Content-Length: ' . filesize($filename)); // provide file size header('Connection: close'); readfile($filename); // push it out exit; } else { $theme->process_404(); } return; }