Jump to content

MP3 Upload, Security and Validation.


jscix

Recommended Posts

Okay, This is the first time I've attempted creating anything beyond a simple image upload.

I would appreciate any helpful tips for ways to maximize validation for mp3 files.

 

Beyond using,

 

$_FILES["uploadedfile"]["type"]

 

What ways can I make sure, the file is an valid mp3 file?

 

Much appreciation in advance..

Link to comment
Share on other sites

<?php
$name = pathinfo($_FILES['uploadedfile']['name']);

if (strtolower($name['extension']) != "mp3") {
    die("Not a valid type");
}
?>

 

I am not sure if the tmpname is correct or not, but yea that is the idea.

 

EDIT: Changed to name due to glyde's comment.

Link to comment
Share on other sites

yeah, i've created a function to validate the extention,

 

Function ValidateFileXT($string) {

$trimstr = substr($string, -4); 
$xt = strstr($trimstr, '.');

if (!$xt){
return False;
}
else {
return $xt;
}
}

 

eg:

$file = strtolower(basename($_FILES['uploadedfile']['name']));

if (ValidateFileXT($file) == ".mp3") {

//yay

}

 

but I was thinking more in terms of actual validation, I think I remember reading that the GD lib. Has a function: exif_imagetype()

 

"exif_imagetype() reads the first bytes of an image and checks its signature."

 

How difficult would this be to do with an mp3?

 

 

Link to comment
Share on other sites

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.