Page 1 of 1

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

Posted: Mon Apr 07, 2003 8:55 am
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

Posted: Mon Apr 07, 2003 9:03 am
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>

Posted: Mon Apr 07, 2003 1:58 pm
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