views:

16

answers:

0

hi all,

I wanted to ask here is my problem. I had implemented the code main task is to raise the files uploaded to the server my site ....

And you want to do now is add a function header http://php.net/manual/en/function.header.php

that will help me and give me the download feature.

Because in the my code is not contain header function and the download is only once you click on the name of the file, but the problem was that if the uploaded file is word file and click it then a window is open to tell me if you want to open the file or save other header file type, such as images not show me the window When I do so special by clicking on the name of the image directly and not appear open the window.

So I decided to add this header function but you still have a problem with it ... The problem is where the correct location where I have to put it between the lines of code .... How do I link between the name of the file and this window

part of code :

$uploadDir ='upload/';

if(isset($_POST['upload']))
{

$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$error =$_FILES['userfile']['error'];


if ($error >0)
    die (" faild");

if (file_exists($uploadDir.$fileName))
    $fileName = rand(10,99).'_'.$fileName;
else
    $fileName = $fileName;

$UploadCategory= "F"; 

$filePath = $uploadDir.$fileName;

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

if (!$result) 
    echo "faild </br>";

include ('connect.php'); 
$query = "INSERT INTO uploads (UploadName, UploadCategory, Link,RoomID,MemberID ) ".
"VALUES ('$fileName', '$UploadCategory', '$filePath','1','$id')";

mysql_query($query) or die('Error, query failed : ' . mysql_error());

another part from anoter file .

while($rows=mysql_fetch_array($result)){
?>

<tr>
<td align="center" bgcolor="#FFFFFF"><input name="checkbox[]" type="checkbox" id="checkbox[]" value="<?php echo $rows['UploadID']; ?>"></td>

<td bgcolor="#FFFFFF"><?php echo $rows['MemberName']; ?></td>
<td bgcolor="#FFFFFF"><?php echo "<a href ='{$rows['Link']}'>{$rows['UploadName']}</a> "; ?></td>

header function >>> where the correct location and How is the link between this function and the name of the file so that you click on the file name I want to take windows show me

/*Set headers
         header("Pragma: public"); 
        header("Cache-Control: maxage=1"); //In seconds

       //header("Cache-Control: no-store, no-cache, must-revalidate");
    //header("Pragma: no-cache");
     header("Content-Description: File Transfer");
     header("Content-Disposition: attachment; filename=\"".$fileName."\";");
     header("Content-Type:$fileType");
     header("Content-Transfer-Encoding: binary");

     // Read the file from disk
      readfile($fileName);

  */

thanks alot for all.