Saving and retrieving documents with invalid characters

Okay, so I’ve modified my script so it creates a file with the chosen name, and it checks file_exists()

$title = 'test a';
$name  = rawurlencode($title) . '.pdf';
copy('test.pdf', $name);
echo '<p>Title: ', $title, '</p>', PHP_EOL;
echo '<p>Name: ', $name, '</p>', PHP_EOL;
if (file_exists($name))
  echo '<p>File ', $name, ' exists!';
echo '<p><a href="', $name, '">', $title, '</a></p>', PHP_EOL;

It tells me the file does exist, but when I click on the link I get a 404! :upside_down_face:

Are copy() and file_exists() working in the same space in terms of virtual vs. absolute (filesystem) paths? Don’t forget your href link is a virtual path.

1 Like

I made sure everything is in the same directory to avoid any problems with relative paths.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.