I am currently building something like a cloud. So the users can upload stuff and then of course download it again. Right now most of it works fine, but I noticed that there is a problem with files which contain a "#" in their name.
For example the file Name could be: "Double Color #2.jpg"
With the variable "$placeoffile" I want to link directly to the file.
My code looks like this:
<?php
if (is_dir($dir)){
if ($dh = opendir($dir)){
while (($file = readdir($dh)) !== false){
if($file != "." && $file != ".."){
$extension = pathinfo($file, PATHINFO_EXTENSION);
$size = filesize($dir.$file);
$placeoffile = $dir.$file;
echo("
<td><a href='$placeoffile'>filename: $file </a></td>
<td>$extension</td>
<td>$size</td>
<td>$placeoffile</td>
<tr>");
}
}
closedir($dh);
}
}
?>
I get the error "Double Color was not found on this server." so somehow everything after the hashtag has been deleted from the search and therefore it obviously didn't find it.
Tried htmlspecialchars and preg but I dont want to rename the files of the users or show a error message to them if they upload a file with a weird name. I feel like there is an easy solution to this, but I just don't see it. Any help? Cheers :)