开发者

Http download stream in PHP and MySQL

开发者 https://www.devze.com 2022-12-09 10:33 出处:网络
How can I read from mysql and write the same in http output stream. So its like if send a request http://www.xyz.com/download/A

How can I read from mysql and write the same in http output stream.

So its like if send a request http://www.xyz.com/download/A it should return me data for A from mysql through php.

The data is plain text.

Thanks PS: I am n开发者_StackOverflowew to php.


Check out the tutorial over at:

http://www.freewebmasterhelp.com/tutorials/phpmysql


This should work, just adapt it to your code by replacing the variables, table and column nammes with yours.

$sql = 'SELECT text FROM table WHERE id='.$id;

$result = mysql_query($sql, $conn) or die('SQL error');
$text = mysql_result($result);

header('Content-Type: text/plain');
echo $text;

Note, that you should not output any HTML or whitespace before sending the header, though.

Hope this helps.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号