Forum Moderators: coopster

Message Too Old, No Replies

opening an uploaded file in server

         

lindaonline15

8:34 am on Nov 15, 2008 (gmt 0)

10+ Year Member



hi all. I have an upload page that uploads some files in my WAMP server and saves link of each file in database. also, I have a search page which I can search for those files and should be able to open them. firefox could not open the files and I changed the way of saving files to this method: $uploadDir = 'file:///C:/wamp/www/newweb/ExamPapers/';
previously, when I was not using file:/// firefox alerted an error in attempting to open. but now, it does not do any reaction and does not open.

in upload page I save the file with these codes:

$uploadDir = 'file:///C:/wamp/www/newweb/ExamPapers/';

if(isset($_POST['upload']))
{
$fileName = $_REQUEST[subject_name];
$tmpName = $_FILES['userfile']['tmp_name']; //path to the file
$fileSize = round((($_FILES['userfile']['size'])/1024/1024), 2);
$fileType = $_FILES['userfile']['type'];

// get the file extension first
$ext = ".pdf";

// make the file name
$uniqueName = $_REQUEST[subject_code] ."_". $_REQUEST[semester] ."_". $_REQUEST[year];

//the unique file name for the upload file
$filePath = $uploadDir . $uniqueName . $ext;

$result = move_uploaded_file($tmpName, $filePath);

if (!$result) {
echo "Erro uploading file";
exit;
}

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}

*************************************************************************
and in search page, I refer to them this way:

while ($row = mysql_fetch_assoc( $result ))
{
$sc = $row['Subject_code'];
$sn = $row['Subject_name'];
$dep = $row['Department'];
$sem = $row ['Semester'];
$y = $row['Academic_Year'];
$size = $row['file_size'];
$link = $row['file_path'];


print("<tr>");
print("<td>$sc</td>");
print("<td>$sn</td>");
print("<td>$dep</td>");
print("<td>$sem</td>");
print("<td>$y</td>");
print("<td>$size</td>");
print("<td><a href = \"$link\" target=\"_blank\"><img src=\"../Images/View.png\" alt=\"View exam paper\"></a></td>");
print("</tr>");
}

can anyone tell me whats the problem with opening the file?

Anyango

11:15 am on Nov 15, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Try backslashes

$uploadDir = 'C:\wamp\www\newweb\ExamPapers\';

lindaonline15

3:03 pm on Nov 15, 2008 (gmt 0)

10+ Year Member



backslash does not work to specify path of location in php. besides, I wanted to use file:/// method to be able to open it...
anyway thx for the try...

vincevincevince

4:19 am on Nov 16, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Do you see error messages in your server error log?

You have missed out hte part of the script in which you do the database insert - can I see that?

lindaonline15

4:30 am on Nov 16, 2008 (gmt 0)

10+ Year Member



no, no errors.

actually, I've solved this problem with changing the path saved in database as this:
$urlPath = 'http://localhost/newweb/ExamPapers/'. $uniqueName . $ext;

now it works perfectly.
thanks for the reply.