PHP/MySQL download file -


i using php/mysql in table have column called 'pdf'.

each row has path pdf file on web server, using php code:

$sql="select * table1 customer_sequence = '53' , invoice_number = '1234' , sequence = '7839' "; $rs=mysql_query($sql,$conn) or die(mysql_error()); $result=mysql_fetch_array($rs);  header('content-disposition: attachment; filename=/path/to/file/'.$result["pdf"].''); header('content-type: application/pdf'); readfile('/path/to/file/'.$result["pdf"].''); 

the sql working ok, once tries download not doing anything.

i have tried:

header("location: /path/to/file/".$result["pdf"].""); 

but still no luck - ideas can do?

okay, let's sort out. @ first, shouldn't output full path file in header. use this:

header('content-disposition: attachment; filename='.$result["pdf"]); 

filename in header tells browser filename should use save file.

second, readfile() doesn't follow path browser uses when paste url. readfile() uses document_root. more information can read answer example: document root php

edit code should this:

$sql="select * table1 customer_sequence = '53' , invoice_number = '1234'     , sequence = '7839' "; $rs=mysql_query($sql,$conn) or die(mysql_error()); $result=mysql_fetch_array($rs);  header('content-disposition: attachment; filename='.$result["pdf"]); header('content-type: application/pdf'); readfile($_server['document_root'] . '/path/to/file/'.$result["pdf"]); 

Comments

Popular posts from this blog

android - getbluetoothservice() called with no bluetoothmanagercallback -

sql - ASP.NET SqlDataSource, like on SelectCommand -

ios - Undefined symbols for architecture armv7: "_OBJC_CLASS_$_SSZipArchive" -