view file

Hi. I uploaded my file to a directory and the filename is saved in MySQL database, how do I view my file? My code not viewing but displays just file name.

ps: the file is in html and PDF format.

<?php

	mysql_connect("localhost", "user", "paswod") or die(mysql_error());
	mysql_select_db("db_name") or die(mysql_error());

$data = mysql_query("SELECT file_name FROM client_file WHERE username = 'john'") or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data ))
{
//Outputs the page

Echo "<b>File Name:</b> ".$info['file_name'] . "<br> ";
}

?>

I guess this forum ain’t the right place to seek help and improvement. Everyone false here is just like me; a tiro

I guess this ain’t the right forum to seek help and improvement. Everyone else here is just like me: a tyro.

That doesn’t output page, just displays what’s stored in the database. If you want to view it, then you probably just need to use a simple include.
[php]<?php
mysql_connect(“localhost”, “user”, “paswod”) or die(mysql_error());
mysql_select_db(“db_name”) or die(mysql_error());

$data = mysql_query(“SELECT file_name FROM client_file WHERE username = ‘john’”) or die(mysql_error());
//Puts it into an array
while($info = mysql_fetch_array( $data )){
//Outputs the page
Echo "File Name: ".$info[‘file_name’] . "
";
include $info[‘file_name’];
}?>[/php]

thanks. but still didn’t work.
error msg: warning: include(file_name) failed to open stream: no such file or directory

That error should be obvious as to its meaning. My example was based on the path being saved in the database, which i guess isn’t the case. So, if the file isn’t in the same folder as the page viewer, then you need to tell it where it is.
[php]include ‘directory/’.$info[‘file_name’];[/php]

hi. thank very much. I noticed the problem I’ve been having was due to my PHP.ini configuration. allow_url_include was off and when I turned it on viola; it worked! now I am wondering if I should eventually go live will my host server have allow_url_include turned on? if they don’t how do I get the script to work?
secondly, I had to manually hard code the path cos I tried something like: $path = ‘localhost/directory/file.htm’; but it wasn’t recognizing the path. is there a way I could define the path instead of using the directory structure?

thanks

The host should have it enabled. The host should have the path defaulted to you domain root. So any path that you use be relative to that.

Sponsor our Newsletter | Privacy Policy | Terms of Service