Specify File type

Reply

Join Date: Aug 2006
Posts: 77
Reputation: dss is an unknown quantity at this point 
Solved Threads: 0
dss's Avatar
dss dss is offline Offline
Junior Poster in Training

Specify File type

 
0
  #1
Oct 12th, 2006
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 "<br>File uploaded<br>";
}
?>
<form action="" method="post" enctype="multipart/form-data" name="uploadform">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
Reply With Quote Quick reply to this message  
Join Date: Sep 2006
Posts: 44
Reputation: MCP is an unknown quantity at this point 
Solved Threads: 3
MCP MCP is offline Offline
Light Poster

Re: Specify File type

 
0
  #2
Oct 14th, 2006
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.
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



Tag cloud for PHP
About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC