Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

file_exists with the ' character

Status
Not open for further replies.

Sebs

Programmer
Jan 3, 2002
17
0
0
AR
My problem is really simple, but is has stolen too much sleeping time and Google has not given any ansewr.
I have a image gallery page, where the user uploads his files, and he can see a Thumbnail. That far it is all working.
The problem appears when the user has a file with a ' char in it's name (exp: "Dady's new car"). The PHP script can't find the file and therefore doesn't show it.
I'm sure the solution is very simple, but I have run out of ideas.

Sebas
 
Thanks, but it didn't work
 
Let's see the code that doesn't work. Can't help by telepathy. :)

Ken
 
It is a little more complex than this, but basically this is what it does, gets the full path of a file and checks if it exists and shows it.
Code:
$file  = $_GET['file'];

if (file_exists($file))
{
    ShowPic($file);
}
It works fine almost all the time, but when the file's name has a ' in it, the file_exists returns false, when I know for a fact that it exists.
If I comment the file_exists(), the fopen() fails.
I hope this is a little more clear.

Sebas.
 
use stripslashes()

the problem seems to be magic qoutes problem...

Known is handfull, Unknown is worldfull
 
As vbkris says, use stripslashes. Your code then becomes:
Code:
$file  = [COLOR=red]stripslashes([/color]$_GET['file'][COLOR=red])[/color];

if (file_exists($file))
{
    ShowPic($file);
}

Ken
 
That did the trick.

Thanks.
 
sebs:
On upload, I make your script clean out un-wanted characters.

Why?

If someone from, let's take my country, Norway, uploads the file "æ_vil_færra_tæ_mexico.jpg", other browsers will not be able to see the characted æ (æ).

They can then not see it in theire browser!

You should remove all characters that are not "standard".
I would remove anything but: a-z, A-Z, 0-9 and some characters like: -, _

eg. I would not allow a filename like: "the.picture.jpg" or "the picture.jpg" and not "the picture` øååæ.jpg" etc.


Olav Alexander Mjelde
Admin & Webmaster
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top