Connecting Tech Pros Worldwide Help | Site Map

Problem in reading a file from database

Member
 
Join Date: Oct 2007
Posts: 83
#1: Nov 23 '07
Hi guys, i have a php file to read to content, the following is the code
[PHP]
<?php
include "config.inc.php";
include "connect.inc.php";

if(isset($_GET['id']))
{
$id = $_GET['id'];
$query = "SELECT filename, filetype, filesize, content FROM candidate_table where id = '$id'";
$result = mysql_query($query) or die(mysql_error());

list($filename, $type, $size, $content) = mysql_fetch_array($result);
$file = fopen($filename,"r") or exit("unable to open");
echo "<div style=\"border:1px blue solid; \">";
while(!feof($file))
{
echo fgets($file);
}
fclose($file);
echo "</div>";
/*
header("Content-length:$size");
header("Content-type:$type");
header("Content-Disposition:attachment; $filename=$name");
echo $content;*/
exit;
}

?>
[/PHP]
but, when run the scripts, it showing the following error,

[HTML]
Warning: fopen(drgulrez[02,00][2].doc) [function.fopen]: failed to open stream: No such file or directory in C:\wamp\www\dr_resume_databse\cv.php on line 12
unable to open
[/HTML]
i m not able to fine the solution, if any one can help, plz help me thanks
Newbie
 
Join Date: Nov 2007
Posts: 20
#2: Nov 23 '07

re: Problem in reading a file from database


presumably drgulrez[02,00][2].doc is actually a file? Also it might be best using a server path to the file in fopen as well.
Member
 
Join Date: Oct 2007
Posts: 83
#3: Nov 23 '07

re: Problem in reading a file from database


Yes, this is the file, when i run other php file to download the same file its working properly, but when i try to open the same file its giving the warning that i posted earlier. and how to used server path...i dont have idea for that plz help...

Quote:

Originally Posted by coffear

presumably drgulrez[02,00][2].doc is actually a file? Also it might be best using a server path to the file in fopen as well.

Newbie
 
Join Date: Nov 2007
Location: Canada
Posts: 9
#4: Nov 23 '07

re: Problem in reading a file from database


on the line after your list() function call you could manip your filename variable to have the path included.. ie:

$filename = "C:\wamp\www\dr_resume_databse\" . $filename;
Member
 
Join Date: Oct 2007
Posts: 83
#5: Nov 24 '07

re: Problem in reading a file from database


Thanks.. for the reply.. . i got the solution.. and thanks for guiding me ...
Quote:

Originally Posted by assimlation

on the line after your list() function call you could manip your filename variable to have the path included.. ie:

$filename = "C:\wamp\www\dr_resume_databse\" . $filename;

Reply