954,193 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Have something to say? Contribute New Article Reply to this Article

Specify File type

Hi,
I am just using a upload script and need to specify that only audio files are uploaded no video or images or any other file.
Only audio files must be loaded.
Can any body provide me the solution for that.
Thankyou

SCRIPT using

<?
// you can change this to any directory you want
// as long as php can write to it
$uploadDir = 'C:/webroot/upload/';

if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
// the files will be saved in filePath
$filePath = $uploadDir . $fileName;
// move the files to the specified directory
// if the upload directory is not writable or
// something else went wrong $result will be false
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}

include 'library/config.php';
include 'library/opendb.php';
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$query = "INSERT INTO upload2 (name, size, type, path ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
mysql_query($query) or die('Error, query failed : ' . mysql_error());
include 'library/closedb.php';

echo "
File uploaded
";
}
?>



dss
Junior Poster in Training
77 posts since Aug 2006
Reputation Points: 10
Solved Threads: 0
 

I think the standard way is to check the file extension, or to check the mime type.

Of course, none of this guarantees that the uploaded file is a valid "audio" file. (What is an audio file for you? MP3, WAV, OGG, etc..????). Depending on your app, this may allow certain people to trade files that are not audio files, just by adding a fake .mp3 extension such as renaming somefile.zip to somefile_zip.mp3.

MCP
Light Poster
44 posts since Oct 2006
Reputation Points: 14
Solved Threads: 3
 

This article has been dead for over three months

Post: Markdown Syntax: Formatting Help
You