PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
<?php
$filesPath = "./";
function securityCheck($name)
{
$wyr = "^[a-z0-9_-]+(\.[a-z0-9_-]+)*$";
return eregi($wyr, $name);
}
function send($fileName, $filePath)
{
if(!file_exists($filePath.$fileName)){
echo('File does not exit on Server!');
return;
}
$fd = fopen($filePath.$fileName,"r");
$size = filesize($filePath.$fileName);
$contents = fread($fd, filesize($filePath.$fileName));
fclose($fd);
header("Content-Type: application/octet-stream");
header("Content-Length: $size;");
header("Content-Disposition: attachment; filename=$fileName");
echo $contents;
}
if(isSet($_GET['name'])){
if(!securityCheck($_GET['name'])){
echo('File does not exit on Server!');
}
else{
send($_GET['name'], $filesPath);
}
}
else{
echo('File does not exit on Server!');
}
?>
First file work ok and list everything from folder second when I click to dowlnoad show so File does not exit on Server! I can't find mistake. Can U help me?