hi all,
i had a upload page and a down load page. so when we upload a file that wil get displayed in a table and a download link wil be beside that file. everything is fine wit upload but wen i click on download link i am getting an error. so please any one can..
thank u...

----download.php-------

<?php
                                 
$path = $_SERVER['DOCUMENT_ROOT']."/Project/$dir/$projectname/$dirname/"; 
$fullPath = $path.$_GET['f1'];
if ($fd = fopen ($fullPath, "r")) 
    {
        $fsize = filesize($fullPath);
        $path_parts = pathinfo($fullPath);
        $ext = strtolower($path_parts["extension"]);
        switch ($ext) 
        {
        case "pdf":
            header("Content-type: application/pdf"); 
            header("Content-Disposition: attachment; filename=\"".$path_parts["basename"]."\""); 
        break; 
        default;
            header("Content-type: application/octet-stream");
            header("Content-Disposition: filename=\"".$path_parts["basename"]."\"");
        }
        header("Content-length: $fsize");
        header("Cache-control: private");  
    while(!feof($fd)) 
    {
        $buffer = fread($fd, 2048);
        echo $buffer;
    }
}
fclose ($fd);
exit;

?>

----upload.php----

<?php  
ob_start();
@session_start();
require_once ("check.php");
$con=mysql_connect("10.70.2.137","invensis","invensis");
if(!$con)
    {
             die('Could not connect: ' . mysql_error());
    }
mysql_select_db("database_myproject",$con); 
$id=$_POST[fileid];
 

$filename=$_FILES['uploaded']['name']; 
$s=($_FILES['uploaded']['size']);
$a= round($s/1024,2); 
$size=round($s/1024,2)." kb";
$answer=$_SESSION[answer];

 $usedmemory=$_POST['usedmemory'];
 $allocatedmemory=$_POST['data1'];
  $remainingmemory=$_SESSION['data3']; 
   
  if($a < $remainingmemory)
   {
   $sql="insert into files(filename,size,uploadedby,projectname) values ('$filename','$size','$_SESSION[username]','$_SESSION[answer]')";
   mysql_error();
   $result = mysql_query($sql);
   $dirname=$_SESSION[username];
   $sql2="select reportingto from users where username='$_SESSION[username]'";
   mysql_error();
   $result2 = mysql_query($sql2);
   if (mysql_num_rows($result2) > 0) 
   { 
        while($row = mysql_fetch_row($result2)) 
        { 
            $admin=$row[0];
        }
   }     
   $dir=$admin;
   $projectname=$_SESSION[answer];
        if(is_dir($dirname)) 
        {             
            $target = "$dir/$projectname/$dirname/";
            $target = $target . basename( $_FILES['uploaded']['name']);
            $ok=1; 
            if ($ok==0) 
            { 
                echo "Sorry your file was not uploaded"; 
            } 
            else 
            {    
                if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
                { 
                    echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";
                     
                } 
                else 
                { 
                    echo " "; 
                }  
            }
        }
        else
        {
            $path="$dir//$projectname//$dirname";
            @mkdir($path,0777,true);
            $target = "$dir/$projectname/$dirname/";
            $target = $target . basename( $_FILES['uploaded']['name']);
            $ok=1; 
            if ($ok==0) 
            { 
                echo "Sorry your file was not uploaded"; 
            } 
            else 
            { 
                if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
                { 
                    echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded"; 
                    
                } 
                else 
                { 
                    echo " "; 
                } 
            }
        }
   }
  else
   {
       echo "<strong style='color:#FF3333'>"."<left><h1>Insufficient Memory.</h1></left>"."</strong>";
  }    
     
    
     ?>

and the error is

Warning: fopen(C:/Program Files/Apache Group/Apache2/htdocs/Project////qhdebug.log) [function.fopen]: failed to open stream: No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\Project\download.php on line 5

Warning: fclose(): supplied argument is not a valid stream resource in C:\Program Files\Apache Group\Apache2\htdocs\Project\download.php on line 28

You should check the value of 'f1'. See that it is appended to $fullpath (in download.php) but the result is an illegal path. There are too many forward slashes in this part of the path:

Project////qhdebug.log

You should check the value of 'f1'. See that it is appended to $fullpath (in download.php) but the result is an illegal path. There are too many forward slashes in this part of the path:

Project////qhdebug.log

i think the error might be some where in this path in download.php

$path = "/$dir/$projectname/$dirname/";

due to that path only i think the error is cuming...

Did some research on this. If you are running it on Windows the correct full path inside your php script should be: "C:\\Program Files\\Apache Group\\Apache2\\htdocs\\Project\\qhdebug.log"
You can always test this by inserting

$fullpath = "C:\\Program Files\\Apache Group\\Apache2\\htdocs\\Project\\qhdebug.log";

between lines 4 and 5.

And change line 3 to

$path = $_SERVER['DOCUMENT_ROOT']."\\Project\\".$dir."\\".$projectname."\\".$dirname."\\";
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.