what's the best way of checking the name of a file to ftp?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
VisionsOfCody
Forum Commoner
Posts: 30
Joined: Sat Mar 01, 2003 1:19 pm
Location: France

what's the best way of checking the name of a file to ftp?

Post by VisionsOfCody »

Hi
I'm writing a bit of code to upload files by ftp - it works on most files but sometimes, if the file name has unacceptable characters, it just won't do it and i get an error message. As the users won't necessarily be very good with computers i'd like to find a foolproof way of sorting this out ...

what do i need to use to check if the file name contains characters that aren't 0-9, a-z (without accents) or 'underscore' ? I had one file that contained an apostrophe that uploaded ok but the filename was changed when it went into the database (a slash was added before the apostrophe) so it couldn't find the file afterwards to unlink it.

Then, is it possible to change the actual filename - replacing all the dodgy characters with an underscore, for example ? Or do i have to settle for putting up a message telling the user to change the filename?

thanks for any help :D
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

might be wrong but I think the result of urlencode() is suitable for (almost) all implementations of ftp

Code: Select all

<pre>
<?php
$s = 'abc1234.!"§$%&/()=\?´`''#€';
echo $s, "\n", urlencode($s);
?>
</pre>
VisionsOfCody
Forum Commoner
Posts: 30
Joined: Sat Mar 01, 2003 1:19 pm
Location: France

Post by VisionsOfCody »

thank you
i'm not sure i really understand what's happening in that bit of code but now i know about urlencode() i can go and snoop around in the php-for-newbies resources :D
Post Reply