download image using php form -


i need download particular image page using submit button, using form , php submit action, here html , php code

html code

<form name="logo" action="" method="post"> <input type="hidden" name="lgpath" value="images/logo/<?php echo $selpro['lgpat'];?>">     <img src="images/cmplogo/<?php echo $selpro['lgpat'];?>">                    <div><input type="submit" value="<?php echo $selpro['lgname'];?>" name="dwnlg" id="dwnlg"></div></div>     </form> 

php code

<?php     if($_post['dwnlg'])     {         $lgpath=$_post['lgpath'];         header('content-disposition: attachment; filename="'.$lgpath.'"');     } ?> 

i gave path download image header it's downloaded current page file, how can solve it?

try following code download

<?php      if($_post['dwnlg'])     {         $lgpath=$_post['lgpath'];         header("content-type: image/jpeg");           header('content-disposition: attachment; filename="'.$lgpath.'"');           header('content-transfer-encoding: binary');         header('expires: 0');         header("cache-control: public");         header('cache-control: must-revalidate');         header('pragma: public');         header('content-length: ' . filesize($lgpath));         readfile($lgpath);        } ?>   

in content type :

         if image in png format :          header("content-type: image/png");          if image in jpeg format :          header("content-type: image/jpeg"); 

Comments

Popular posts from this blog

c# - SVN Error : "svnadmin: E205000: Too many arguments" -

c# - Copy ObservableCollection to another ObservableCollection -

All overlapping substrings matching a java regex -