...

View Full Version : inserting sound files to DB



mivec
04-29-2004, 05:48 AM
hi all,
errmmm....i am not sure how to do this...i have done uploading of images where i only upload the path of the image.like this:



//checking with this
function checkfile($inputname,$inputsize,$inputtype,$size){
global $error;

if($inputsize==0){
$error[]="Please select a picture for your product!";
}
elseif($inputsize>$size){
$error[]="File size can be maximum ".$size." bytes!";
}
elseif(is_uploaded_file($inputname)){
$file_type=$inputtype;
$allowed_types=array("image/bmp","image/gif","image/pjpeg","image/jpeg");

if(!in_array($file_type, $allowed_types))
$error[]="File type not permitted! (Please use jpg, jpeg, bmp, or gif images)";
}
}




//inserting to database
$uploaddir = "img/userPics/";

if(!file_exists($uploaddir))
{
mkdir($uploaddir, 0777);
}

// check file
checkfile($_FILES['file']['tmp_name'], $_FILES['file']['size'], $_FILES['file']['type'],500000);

if(!isset($error))
{
$date = date("YmdHis");
$done = copy($_FILES['file']['tmp_name'],$uploaddir.$date.'.jpg');
}

if ($done)
{
$query = "INSERT INTO tblgallery (pic_Path, username, pic_Num) VALUES ('" . addslashes($uploaddir) . $date . ".jpg', '" . $_POST["txtUsername"] . "', '" . $num . "')";
mysql_query($query) or
die (mysql_error());


so....i don't know if it can be done the same way for sounds like mp3 or wav or whatever...pls advice..thank you.

litebearer
04-29-2004, 05:50 AM
for all intent and purposes a file is a file, until it is used. So yes, store it in the same fashion you are storing the images. Put the file in a special folder, and simply put its location in the database.

ConfusedOfLife
04-29-2004, 01:21 PM
Yes, I agree, there shouldn't be any difference between files. But then let's change the question a little bit now that we know how to upload sound files: Is there any useful function like getImageSize that we had for image files to make sure what we're getting is truly a sound file and possibly get it's length and other stuff? If we didn't have getImageSize then it's no way to find out a file is truly an image, even checking for the file extension doesn't help coz it can easily be faked. Wuddya think?

litebearer
04-29-2004, 02:20 PM
from:

http://us4.php.net/filesize



<?PHP

// outputs e.g. somefile.txt: 1024 bytes

$filename = 'somefile.txt';
echo $filename . ': ' . filesize($filename) . ' bytes';

?>


Lite...

ConfusedOfLife
04-30-2004, 10:08 AM
Did you notice this:



even checking for the file extension doesn't help coz it can easily be faked. Wuddya think?



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum