how do you open a file with quote marks in the file name on Linux?

how do you open a file with quote marks in the file name on Linux?

am 19.10.2007 02:38:02 von Jake Barnes

I've got a client that is a music studio and they've several thousand
mp3s that tend to have file names like this:

Adrian Orange - Bitches Is Lord - 13 - Don't Get Used To It.mp3

The quote mark in that file name is giving me trouble.

The music studio asked me to write a script that could read all the
metadata out of their mp3s and then store the info in a database.
Using the getID3 library, I've had an easy time with all the files
that don't have quote marks in their names:


require_once('../getid3/getid3/getid3.php');
$getID3 = new getID3;

for ($i=0; $i < count($formInputs); $i++) {
$originalFileName = $formInputs[$i];
$fileNameWithSlashesAdded = stripslashes($originalFileName);
$fileNameWithSlashesAdded = addslashes($fileNameWithSlashesAdded);

$filePath = "../site_specific_files/".$fileNameWithSlashesAdded;

if (! @ file_exists($filePath)) {
$controller->addToResults("We were not able to import '$filePath'.
Usually this means the software stumbled over an unusual character in
the file name.");
return false;
}
// Analyze file and store returned data in $ThisFileInfo
$ThisFileInfo = $getID3->analyze($filePath);


This works fine, except when there is a quote mark in the file name.
I've tried using addslashes, and I've tried not using addslashes, and
I've tried using addslashes twice.

No dice. Nothing works.

This is on a server running RedHat Linux.

Suggestions?

Re: how do you open a file with quote marks in the file name on Linux?

am 19.10.2007 03:05:02 von Jake Barnes

On Oct 18, 8:38 pm, lawrence k wrote:
> I've got a client that is a music studio and they've several thousand
> mp3s that tend to have file names like this:
>
> Adrian Orange - Bitches Is Lord - 13 - Don't Get Used To It.mp3
>
> The quote mark in that file name is giving me trouble.
>
> The music studio asked me to write a script that could read all the
> metadata out of their mp3s and then store the info in a database.
> Using the getID3 library, I've had an easy time with all the files
> that don't have quote marks in their names:
>
> require_once('../getid3/getid3/getid3.php');
> $getID3 = new getID3;
>
> for ($i=0; $i < count($formInputs); $i++) {
> $originalFileName = $formInputs[$i];
> $fileNameWithSlashesAdded = stripslashes($originalFileName);
> $fileNameWithSlashesAdded = addslashes($fileNameWithSlashesAdded);
>
> $filePath = "../site_specific_files/".$fileNameWithSlashesAdded;
>
> if (! @ file_exists($filePath)) {
> $controller->addToResults("We were not able to import '$filePath'.
> Usually this means the software stumbled over an unusual character in
> the file name.");
> return false;
> }
> // Analyze file and store returned data in $ThisFileInfo
> $ThisFileInfo = $getID3->analyze($filePath);
>
> This works fine, except when there is a quote mark in the file name.
> I've tried using addslashes, and I've tried not using addslashes, and
> I've tried using addslashes twice.
>
> No dice. Nothing works.
>
> This is on a server running RedHat Linux.
>
> Suggestions?


Oh, strange. Apparently I just needed stripslashes. That's all. So
weird.

Re: how do you open a file with quote marks in the file name on Linux?

am 19.10.2007 03:34:58 von Michael Fesser

..oO(lawrence k)

>On Oct 18, 8:38 pm, lawrence k wrote:
>
>> I've got a client that is a music studio and they've several thousand
>> mp3s that tend to have file names like this:
>>
>> Adrian Orange - Bitches Is Lord - 13 - Don't Get Used To It.mp3
>>
>> The quote mark in that file name is giving me trouble.
>>
>> The music studio asked me to write a script that could read all the
>> metadata out of their mp3s and then store the info in a database.
>> Using the getID3 library, I've had an easy time with all the files
>> that don't have quote marks in their names:
>> [...]
>>
>
>Oh, strange. Apparently I just needed stripslashes. That's all. So
>weird.

I don't think so. You should only need stripslashes() if magic quotes
are enabled (can be checked with get_magic_quotes_gpc()) to remove them.
No magic quotes, no stripslashes().

Micha

Re: how do you open a file with quote marks in the file name on Linux?

am 19.10.2007 20:47:43 von Jake Barnes

On Oct 18, 9:34 pm, Michael Fesser wrote:
> .oO(lawrence k)
>
>
>
> >On Oct 18, 8:38 pm, lawrence k wrote:
>
> >> I've got a client that is a music studio and they've several thousand
> >> mp3s that tend to have file names like this:
>
> >> Adrian Orange - Bitches Is Lord - 13 - Don't Get Used To It.mp3
>
> >> The quote mark in that file name is giving me trouble.
>
> >> The music studio asked me to write a script that could read all the
> >> metadata out of their mp3s and then store the info in a database.
> >> Using the getID3 library, I've had an easy time with all the files
> >> that don't have quote marks in their names:
> >> [...]
>
> >Oh, strange. Apparently I just needed stripslashes. That's all. So
> >weird.
>
> I don't think so. You should only need stripslashes() if magic quotes
> are enabled (can be checked with get_magic_quotes_gpc()) to remove them.
> No magic quotes, no stripslashes().


I guess magic quotes were enabled. It's an old installation, from 3 or
4 years ago, so the server probably adheres to a lot of old practices.
Or maybe it has whatever defaults RedHat Linux shipped with 3 years
ago.

But I did hit the file name with stripslashes, and suddenly the code
worked.