setAttribute( PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION ); } catch(PDOException $e) { die($e->getMessage().$p_dbpath); } } function send_file($name, $ruta) { global $SQLDB; $status = FALSE; $path = $ruta.'/'.$name; $speed=200; $size = filesize($path); if (!is_file($path) or connection_status()!=0) return(FALSE); header("Content-type: application/octet-stream"); header("Content-Disposition: attachment; filename=\"".str_replace("?","",str_replace(":","",$name))."\""); header("Content-length: ".(string) $size); header("Last-Modified: ".gmdate("D, d M Y H:i:s")." GMT"); header("Cache-Control: no-cache, must-revalidate"); header("Pragma: no-cache"); header("Content-Description: Bajando de Dantoine"); if ($filez = fopen($path, 'rb')) { while(!feof($filez) and (connection_status()==0)) { echo fread($filez, round($speed*1024)); flush(); sleep(1); } $status = (connection_status()==0); fclose($filez); } return($status); } $db_path = "/home/dantoine/http_docs/www_blog/dbm1026/"; // db path $db_name = "downloads.db"; // Database name ConnectOrDie($db_path.$db_name); $sql = "SELECT * FROM downloads WHERE id = ?"; $q = $SQLDB->prepare($sql); $q->execute(array($_GET['dw'])); $row = $q->fetch(PDO::FETCH_ASSOC); if(!isset($row['id'])) { die("..."); } else { //echo $row['id']; $url_info = parse_url($row['filename']); $file_info = pathinfo($url_info['path']); $sql="UPDATE downloads SET hits=hits+1 where id = ?"; $q = $SQLDB->prepare($sql); $q->execute(array($_GET['dw'])); $count = $q->rowCount(); if(!$count) { die('Fallo al buscar informacion sobre el download'. " $count \n". __LINE__. ' '.__FILE__. " \n".$sql); } send_file($file_info['basename'], "/home/dantoine/piecrust.base".$file_info['dirname']); } ?>