0

hi i am new to php. i am getting the following error
----Warning: fopen(C:/Program Files/Apache Group/Apache2/htdocs/Project/) [function.fopen]: failed to open stream: No such file or directory in C:\Program Files\Apache Group\Apache2\htdocs\Project\download.php on line 4----
----Warning: fclose(): supplied argument is not a valid stream resource in C:\Program Files\Apache Group\Apache2\htdocs\Project\download.php on line 27------

<?php
$path = $_SERVER['DOCUMENT_ROOT']."/Project/"; 
$fullPath = $path.$_GET['filename'];
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;

?>

Edited by niths: n/a

2
Contributors
1
Reply
2
Views
7 Years
Discussion Span
Last Post by n_e
0

>> failed to open stream: No such file or directory

It's trying to open "C:/Program Files/Apache Group/Apache2/htdocs/Project/" which isn't a file as you can see and that's why it failed. This means that $_GET['filename'] doesn't contain a value.

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.