0

I have a following code for download option:

<a href='http://xyz.net/video/<?php echo $row['video_name']?>' 
title='click to download this video'>
<img src="resources/images/icons/download.png"/>

Which works fine.

Now, I want to update my download table as

UPDATE video_uploaded SET downloaded = 1 WHERE video_id = '211' 
//here video_id is dynamic and it's not a problem

How is it possible to add redirect to another page option on this snippet:

<a href='http://xyz.net/video/<?php echo $row['video_name']?>'  
title='click to download this video'> 
<img src="resources/images/icons/download.png"/>

so that when user clicks on Download button first it downloads the file and then updates the table.

Vijaya Pandey
  • 4,252
  • 5
  • 32
  • 57

1 Answers1

0

I'd do something like this:

<a id='mylink' href='http://xyz.net/video/<?php echo $row['video_name']?>'  
title='click to download this video'> 
<img src="resources/images/icons/download.png"/>

And then using jQuery call the script to update the table:

$('#mylink').click(function(){
 $.post('script.php');
});

EDIT:

Due to the comments about checking successful download I'd try this:

$('#mylink').click(function(){
    $.post('downloadScript.php', function(data){
    if(data){
       $.post('updateScript.php');
     }
     else{
       // do whatever on failed download
     }
   };
});
Dimag Kharab
  • 4,439
  • 1
  • 24
  • 45
Darius
  • 135
  • 4
  • 1
    how will you know from this that user has successfully downloaded the file or not ? – Rakesh Shetty Mar 27 '14 at 11:31
  • honest attempt , but @RakeshShetty is correct how will you ensure a successful download ? – Dimag Kharab Mar 27 '14 at 11:33
  • to be that strict: I don't know of a solution to find out that the user downloaded the file, for example: user clicks download, confirms by pressing the save button and then cancels the download - how would you go about it? as far as I know you can only check the file was successfully sent to the browser – Darius Mar 27 '14 at 11:37
  • it is difficult to find wheater user has cancel the downloading or not. It is purely based on client side – Rakesh Shetty Mar 27 '14 at 11:46
  • using ignore_user_abort(false) and connection_aborted() ?? – Dimag Kharab Mar 27 '14 at 11:59