Debt - eHarmony Coupon - Houses for Sale - Broadband - Online Advertising

PDA

View Full Version : Php Help - urgent


fakhruddin
Sep 16th 2006, 10:36 am
i am running an image hosting script

when i upload normal images everything is fine


but when i upload images with spaces in between it creates problems

for eg - If i upload "Abc Vbg.jpg"

The Link Comes Like This
http://localhost/photo/Abc+Vbg.jpg

But the correct link to the image is
http://localhost/photo/Abc Vbg.jpg

how do i solve this issue

harsh789
Sep 16th 2006, 11:17 am
Noting wrong in the link. It is urlencoded with space encoded to + sign.

So if you create url for the image Abc Vbg.jpg, it is encoded to Abc+Vbg.jpg

fakhruddin
Sep 16th 2006, 11:40 am
neways probs solved now

thanks neways

discoverclips
Sep 16th 2006, 11:45 am
you should always filter file names.
if somebody uses filenames with weird characters in them, you might not be able to remove them from your server.

use preg_replace to filter the filenames

intoex
Sep 17th 2006, 6:59 am
generate new filename - replace spaces with _ and add some unique value - this will solve the problem

Icheb
Sep 17th 2006, 10:00 am
you should always filter file names.
if somebody uses filenames with weird characters in them, you might not be able to remove them from your server.

use preg_replace to filter the filenames
What filter rule do you need to prevent that from happening?

discoverclips
Sep 17th 2006, 12:22 pm
What filter rule do you need to prevent that from happening?

function cleanfile($file) {
return preg_replace('/[^0-9A-Za-z\- ]/', "", $file);
}

that should work :)

Icheb
Sep 17th 2006, 12:24 pm
Awesome, thank you!