PHP - How To Track The Download Of Pdf Files
I've searched the forum, and haven't yet found what I need.
I have a long list of PDF files: http://www.iampeth.com/vintage_magazines.php How can I track the number of downloads for each file? Similar TutorialsThis topic has been moved to Ajax Help. http://www.phpfreaks.com/forums/index.php?topic=316351.0 Hi Guys I trying to download files and I have this error message, hopelly you guys can help me please
Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 14 Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 15 Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 16 Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 17 Warning: Cannot modify header information - headers already sent by (output started at /home/content/04/12746204/html/Digital/core/inc/init.inc.php:6) in /home/content/04/12746204/html/Digital/download.php on line 18 This is the code I use to force the download <?php include('core/inc/init.inc.php'); if(isset($_GET['file_id'])) { $file_id=(int)$_GET['file_id']; $file=mysql_query("SELECT file_name, file_expiry FROM files WHERE file_id=$file_id"); if(mysql_num_rows($file)!=1){ echo'Invalid file Id'; }else{ $row=mysql_fetch_assoc($file); if ($row['file_expiry']<time()){ echo'This file has expired'; }else{ $path="core/files/{$row['$file_name']}"; header('Content-Type:application/octet-stream'); header('Content-Description:File Transfer'); header('Content-Transfer-Encoding:binary'); header("Content-Disposition:attachment;filename=\"{$row['file_name']}\""); header('Content-Length:'.filesize($path)); readfile($path); } } } ?>Thank you for your help..... Hey guys, im starting out on my php journey with a small question. I have a small uploading site and i want to allow php uploads. Once uploaded, you get a direct upload link, and i want the file to download, rather than execute. How can this be done? Thanks! Hi guys i am kinda stuck at a part where i want a download button to prompt out two download windows in a click. Currently i am able to prompt out one download window only. I have tried putting another header line of Content Disposition but it doesn't work..i will appreciate if you guys can help me out, thanks! The desired scenario will be WinSCP.exe download prompt will appear first, follow by auditgroup.bat $file1 = "WinSCP.exe"; $file = "auditgroup.bat"; //Set headers header("Cache-Control: private"); header("Expires: 0"); header("Pragma: cache"); header("Content-Description: File Transfer"); header("Content-Disposition: attachment; filename=$file"); header("Content-Type: application/octet-stream"); header("Content-Transfer-Encoding: ASCII"); //Read the file from disk readfile($file); Hi PHP Community, I have this class in my DOCMAN script and would like to add aditional functionality to watermark existing PDF files: Code: [Select] class DOCMAN_File { /** * @access public * @var string */ var $path = null; /** * @access public * @var string */ var $name = null; /** * @access public * @var string */ var $mime = null; /** * @access public * @var string */ var $ext = null; /** * @access public * @var string */ var $size = null; /** * @access public * @var string */ var $date = null; /** * @access private * @var string */ var $_err = null; /** * @access private * @var boolean */ var $_isLink; function DOCMAN_File($name, $path) { $path = mosPathName( $path ); if (!is_dir( $path )) { $path = dirname( $path ); } $this->name = trim($name); $this->path = $path; if( strcasecmp( substr( $this->name , 0, _DM_DOCUMENT_LINK_LNG ) , _DM_DOCUMENT_LINK )==0){ $this->_isLink = true; $this->size = 0; $this->mime = 'link'; }else{ $this->_isLink = false; $this->size = filesize($this->path."/".$this->name); $this->mime = DOCMAN_MIME_Magic::filenameToMIME($this->name, false); } $this->ext = $this->getExtension(); } /** * Download or view a file from the server * @desc This is the function handling files downloading using HTTP protocol * @param void * @return void */ function download() { $user_agent = (isset($_SERVER["HTTP_USER_AGENT"]) ) ? $_SERVER["HTTP_USER_AGENT"] : $HTTP_USER_AGENT; //Fixed [#2534] clean all output buffers (needs PHP > 4.2.0) /* while (ob_get_level()) { * ob_end_clean(); }*/ // Fix [3164] while (@ob_end_clean()); if( $this->_isLink ){ header( "Location: " . substr( $this->name , 6 ) ); return; } $fsize = filesize($this->path."/".$this->name); $mod_date = date('r', filemtime( $this->path.'/'.$this->name ) ); $cont_dis = 'attachment;'; if(isset($_REQUEST['mode'])) $cont_dis = ($_REQUEST['mode'] == 'view') ? 'inline;' : 'attachment;'; header("Pragma: public"); header("Cache-Control: must-revalidate, post-check=0, pre-check=0"); header("Expires: 0"); header("Content-Transfer-Encoding: binary"); header('Content-Disposition:' . $cont_dis .'";' . ' filename="' . $this->name . '";' . ' modification-date="' . $mod_date . '";' . ' size=' . $fsize .';' ); //RFC2183 header("Content-Location: ". $this->path . '/' . $this->name ); header("Content-Type: " . $this->mime ); // MIME type header("Content-Length: " . $fsize); // No encoding - we aren't using compression... (RFC1945) // header("Content-Encoding: "); readfile($this->path."/".$this->name); // The caller MUST 'die();' } function exists() { if( $this->_isLink ){ return true; } return file_exists($this->path."/".$this->name); } function isLink(){ return $this->_isLink ; } /** * Get file size * * @desc Gets the file size and convert it to friendly format * @param void * @return string Returns filesize in a friendly format. */ function getSize() { if( $this->_isLink ){ return 'Link'; } $kb = 1024; $mb = 1024 * $kb; $gb = 1024 * $mb; $tb = 1024 * $gb; $size = $this->size; if ($size) { if ($size < $kb) { $file_size = "$size Bytes"; } elseif ($size < $mb) { $final = round($size/$kb,2); $file_size = "$final KB"; } elseif ($size < $gb) { $final = round($size/$mb,2); $file_size = "$final MB"; } elseif($size < $tb) { $final = round($size/$gb,2); $file_size = "$final GB"; } else { $final = round($size/$tb,2); $file_size = "$final TB"; } } else { if( $size == 0 ) $file_size = "Empty!"; else $file_size = "ERROR"; } return $file_size; } /** * @desc Gets the extension of a file * @return string The file extension */ function getExtension() { if( $this->_isLink ) return "lnk"; $dotpos = strrpos($this->name, "."); if ($dotpos < 1) return "unk"; return substr($this->name, $dotpos + 1); } function getDate($type = 'm') { if( $this->_isLink ){ return ""; } $date = ''; switch($type) { case 'm' : $date = filemtime($this->path."/".$this->name); break; case 'a' : $date = fileatime($this->path."/".$this->name); break; case 'c' : $date = filectime($this->path."/".$this->name); break; } return date ("m.d.y - H:i:s", mosFormatDate($date)); } } I found this function on the net and it works fast. But because I'm newbie I have problem in implementing it correctly to class: Code: [Select] function WaterMark($filename){ $tempfile=tempnam('/path/to/directory/tmp,'temp.pdf'); $watermark = "/path/to/directory/htdocs/components/com_docman/includes_frontend/water.pdf"; system("pdftk $filename stamp $watermark output $tempfile dont_ask", $errcode); if (!$errcode && $ih=fopen($tempfile, 'r')) { header('Content-Type: application/pdf'); fpassthru($ih); fclose($ih); } else { print "Whoops"; } unlink($tempfile); } Here is frontend use of class. Code: [Select] $downloadDoc = new DOCMAN_File($document->dmfilename,$_DOCMAN->getCfg('dmpath')); $downloadDoc->download(); For now I only managed to get it working to watermark PDF file for view mode but not before download mode as attachment. Function is working fine by itself but not when integrated in class. I'm getting really frustrated . Please help me!?! Thank you everybody. Al I have a Joomla website having one folder for audio files in it and their links are saved in database. Now I want to show two calendars to the user at front end, so that they can choose that from when to from he want to download the audio files? for e.g he can select june-2-2014 in one calendar and august-2-2014 in second calendar, now on clicking download button the files residing between the two specific dates must get archived into one zip file and then start downloading... i have a reference link for creating a zip and downloading the zip :http://coursesweb.ne...-archive-php_cs now i am stuck that how to get the selection of user from calendar , save it into the array , and from the array get the files from the folder matching the array indexes and then zip , download them. please tell me how to achieve this task ? Hi, how much bandwidth is used for 1000 downloads per day or for each download? Is it safe to have no download limits? Thanks
Basically I would like to place a link on my website and have the user download a file, but rather than just right clicking and choosing save target as, the link must be clicked, on the next page the file is fetched and then the client can download the file. How would I go about setting this up please? Hi,
i am a student for a school.
we have in each class a book that lists the shool year. Teachers use it to make notes in it and mark people that are not present.
i want to bring that whole process online making a website out of it.
Teachers can log in and see the yearbook. Days view, Week view, Month view. Mark people that have been missing on a specific day. List all the people that have been missing during a school week.
How would i present the Calender? Tables?
I have the some knowledge in mysql, php and joomla.
How would i go about getting startet? Do i need to have a Framework?
All ideas would be greatly appreciated.
Thank you
I have a site where people vote, currently if two computers that are on the same network vote, my site will see them as one computer because I only track people by IP address. What would be a good way to track 2+ computers with the same IP address? Hello! I want to build a script to basically keep track of the number of hosting accounts that are currently on each server. I have roughly 30 servers (root access, WHM, cPanel) that I would like to be able to track all of from a single page. Could someone help/point me in the right direction/offer any input? thanks! much appreciated! How can I track session requests, so I can, after a certain number of requests (let's say ten because it's physcologically pleasing), have the id regenerated? Hi everybody,
I want to cloak my affiliate links or mask it so it looks like a pretty url. Also if possible, I want to track the clicked link with Google Analytics so I think I need a page where I can log the click.
I found lots of information but not for the situation I have. I get my links from my database like this:
echo '<a href="'.$info['url'].'">the link</a>';How can I accomplish this? So I need a url like www.mydomain.com/click and when a user click on the link the get a new page with a tracking code and a redirect script to the right url. Thanks so much for the help! Kind regards, Mark So i have a bunch of random videos playig one after the other what i want is to track if the user viewed the videos by inserting a view lets say in to the database, so if they view the first video the database will increment by 1 then after the page refreshes and the next video loads it will increment again, the only part i dont know what im doing is how would i know if my user viewed the video, any help please thank you? Hi all, I followed a tutorial to get the base of a php calendar done, then added some custom Javascript in order to be able to change the color of the cells. The calendar can be seen he http://www.education-world.co.uk/Education%20World%20Site/calendar.php The problem is now, that I need to integrate a SQL database to keep track of what was set for certain dates. I'm not sure of how to even begin this, all i need to do is keep track of if the candidate is available, not available or working for a specific day. The calendar is submitted to an email but this means when they return at a later date (availability may change) their previously set availability will have been wiped! I can provide code if needed. Can anyone help me out here, really struggling with this! Many thanks, Greens85 What is the best way to keep track of a User's (real-time) online status? Right now I have a Log In script and I set the status in the User's Session, and then "pass" that status from page to page with session_start();. However, the problems with this approach include... 1.) A User is idle for hours or days and thus not really online 2.) A User leaves my site and thus is not really online (Or does closing the window change that?) I want a fairly accurate and real-time reading of whether or not a User is actively using my site so I can set their "Online Status" icon as green (online) or yellow (in active) or grey (offline). Any idea how to accomplish that so I have monitoring like you'd see on an Instant Messenger App? Thanks, Debbie Hello,
I have been looking for a way to track the play stats on audio mp3's in the admin of my custom post-type. Whatever I google seems to come up with nothing. I not very versed in audio player code - could someone please point me in the right direction.
Again:
I have a custom post-type which uses the wordpress default audio.
I would like to get the number of plays for each audio file and display that in the admin column for my custom post-type
Thanks,
Drew
Hello friends, I am new to PHP and have developed a website... i am stuck at one place. I want to know if the user changes the url in the adress bar and goes to another webpage.. Can we detect that? This is very important for my website because I calsulate the duration of login based on whether user goes to another page or logs out. I have a table which stores job numbers…each job number can have multiple “line items”…here is a screenshot of example data: https://imgur.com/qSaiJMD I am trying to use another feature of handsontable called nestedRows which makes it look like this: https://imgur.com/lRE6mbq In that example I have setup the JSON with hardcoded data. I am trying to integrate it into my PHP now. I have to make the JSON go from this: https://imgur.com/7hHQvC9 To something like this: https://imgur.com/7bSdl1O I can’t figure out how I can compare the current value in “job_number” to the last row’s “job_number” value so that I can tell the code for example… if($previousRow_job_number == $currentRow_job_number) { //then structure JSON data as a child (line item) of this job number } else { //structure JSON data as a parent job number } This is my current code I am trying to modify: <script type="text/javascript"> /* JSON Construction */ const data = <?php //setup query $sql = 'SELECT * FROM production_data'; //execute SQL transaction try { //prepare SQL statement & execute $stmt = $pdo->prepare($sql); $stmt->execute(); //bind column names to variables $stmt->bindColumn('id', $id); $stmt->bindColumn('job_number', $job_number); $stmt->bindColumn('enterprise', $enterprise); $stmt->bindColumn('part_number', $part_number); $stmt->bindColumn('description', $description); $stmt->bindColumn('qty', $qty); $stmt->bindColumn('line_item', $line_item); $stmt->bindColumn('as400_ship_date', $as400_ship_date); $stmt->bindColumn('date_showed_on_report', $date_showed_on_report); $stmt->bindColumn('shipping_method', $shipping_method); $stmt->bindColumn('notes', $notes); $stmt->bindColumn('date_shown_complete', $date_shown_complete); $stmt->bindColumn('actual_ship_date', $actual_ship_date); $stmt->bindColumn('qty_shipped', $qty_shipped); //output data into spreadsheet view while($row = $stmt->fetch(PDO::FETCH_BOUND)) { //construct array with data $json = array(); while($row = $stmt->fetch(PDO::FETCH_BOUND)) { //$json[] = array($description, $qty, $line_item, $job_number, $as400_ship_date, $date_showed_on_report, "5", $notes, $date_shown_complete, $actual_ship_date, $qty_shipped); $json[] = array($job_number, $line_item, $description, $qty, $as400_ship_date, $date_showed_on_report, "5", $notes, $date_shown_complete, $actual_ship_date, $qty_shipped); } //encode for JSON and output to screen print(json_encode($json)); } } //failed to execute SQL transaction catch (PDOException $e) { print $e->getMessage(); } ?> /* End JSON Construction */ const container = document.getElementById('productionLogTable'); const hot = new Handsontable(container, { data: data, //colHeaders: ['Description', 'Qty', 'LN #', 'Order Number', 'AS400 Ship Date', 'Date Showed on Report', 'Days to Manufacture', 'Notes', 'Date Shown Completed', 'Actual Ship Date', 'Qty Shipped'], colHeaders: ['Job Number', 'LN #', 'Description', 'Qty', 'AS400 Ship Date', 'Date Showed on Report', 'Days to Manufacture', 'Notes', 'Date Shown Completed', 'Actual Ship Date', 'Qty Shipped'], //colWidths: [300, 70, 70, 110, 110, 90, 90, 300, 90, 90], colWidths: [110, 70, 300, 70, 110, 90, 90, 300, 90, 90], rowHeaders: true, headerTooltips: { columns: true, onlyTrimmed: true }, filters: true, dropdownMenu: true, }); </script> I hope I’ve provided enough detail… Edited March 25, 2020 by mongoose00318to make links into actual links I'm interested to know how other people keep track of time and also how they display time correctly back to the users. I'm using a third party API that I can tie into that actually gives me the userID of a user, their full name and the timezone for that user. After checking a few users data, this is an example data of what I'm working with. userID: 234213412 first_name: foo last_name: bar timezone: -6 Basically when a user visits my web app, I create a new account for them and store the above data. Currently, I'm just fetching the result from time() and converting it into MySQL DateTime format and storing that into my database. Code: [Select] //get the current time as an integer $php_timestamp = time(); //formats the time according to MySQL DateTime type $this->mysql_formatted_time = date('Y-m-d H:i:s', $php_timestamp); I would think the current way that I'm doing this is not very good because there is a possibility that I could introduce load balancing servers into the mix and they might not be located in the same region. Also, I would have no idea how to factor the time and modify it according to the timezone value.(in my above example, -6) Can anyone help me decide what method I should use to keep all of my servers timestamps in sync and how to display the time to the end user so that it looks correct to them? |