Jump to content

Recommended Posts

I dont get why you dont want to use substr() function.

 

You could use regular expressions to get extension of the file.

 

But, if you dont want to use substr() here is a way to do it

 

$filename = 'something.wav';
$fl = strlen($filename); // File length
$fileextension = $filename[$fl] . $filename[($fl-1)] . $filename[($fl-2)];
if ( $fileextension == 'wav' ) {
echo 'Valid file extension';
}

 

The downside to this is that the person could just change the extension of the file with a malicious exe inside.

I dont get why you dont want to use substr() function.

 

You could use regular expressions to get extension of the file.

 

But, if you dont want to use substr() here is a way to do it

 

$filename = 'something.wav';
$fl = strlen($filename); // File length
$fileextension = $filename[$fl] . $filename[($fl-1)] . $filename[($fl-2)];
if ( $fileextension == 'wav' ) {
echo 'Valid file extension';
}

 

The downside to this is that the person could just change the extension of the file with a malicious exe inside.

 

I don't know why on earth someone would choose that over substr but regardless, you made a small fubar in judgement.  strlen returns length of string but elements start at 0 not 1 so it would be $fl-1,$fl-2,$fl-3 not $fl,$f-1,$fl-2

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.