View Full Version : inserting sound files to DB

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;

$error[]="Please select a picture for your product!";
$error[]="File size can be maximum ".$size." bytes!";

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/";

mkdir($uploaddir, 0777);

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

$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.

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.

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?

04-29-2004, 02:20 PM



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

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



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?