Thursday, 1 May 2008

Making sure that theres no gaps in the filenames of image uploads.

The problem that needed to solved here was that users could upload there own images - and if the filename they were uploading has gaps or whitespace.
It took me a while to get my head around this one, eventhough the solution is fairly simple.
If you have solving the same problem here are a couple of links that may help. Firstly I posted this problem on a developer network forum. you can see that post at .
A tutorial that helps understand how file upload works in php is

Any back to my code.

What I needed to do first was check to check if theres any spaces and replace with '_'

$img1 = str_replace ( ' ', '_', $img1 );


then in move_uploaded_file change it to

$res = move_uploaded_file($_FILES['img1']['tmp_name'], $abpath .

staright forward, I have no idea now why I couldn't get my head around this straight away.

No comments: