Forum Moderators: coopster

Message Too Old, No Replies

Document upload help.

         

tonynoriega

9:19 pm on Jun 4, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I have a PHP page for document uploading. it sends the file to a mysql dbase to be retrieved and displayed on another page.

I found that if you upload a pdf with a space in the file name, i.e.:

this page.pdf

it uploads without erors, and is even displayed properly on the display page, but when i click on the link to download and view it downloads it as just the first part of the file name, i.e.: "this"

and does not download as a pdf...

is there a way to secure the script so that if someone tries to upload a file with a space in it, it either will not, or can it add an underscore or something...?

looking for a solution.
thanks

eelixduppy

10:02 pm on Jun 4, 2008 (gmt 0)



do a simple string replace on the filename. It's a good idea to not keep the same filenames on upload, anyway, as a security precaution. But what would work is the following to replace the space:

$filename = [url=http://www.php.net/str-replace]str_replace[/url](' ','_',$filename);

tonynoriega

4:28 pm on Jun 5, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



can i put that in this section of my code... (sorry newbie here)
i.e.

if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filename = str_replace(' ','_',$filename);
}