Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 5 of 5
  1. #1
    Regular Coder
    Join Date
    Feb 2004
    Location
    Malaysia
    Posts
    175
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy inserting sound files to DB

    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:

    PHP Code:
    //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)"
        } 

    PHP Code:
    //inserting to database
     
    $uploaddir "img/userPics/"
                        
                    if(!
    file_exists($uploaddir))
                        { 
              
    mkdir($uploaddir0777);
                        } 
                                  
            
    // 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.
    Warm Regards,
    Mivec

  • #2
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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?

  • #4
    Regular Coder
    Join Date
    Apr 2004
    Posts
    298
    Thanks
    0
    Thanked 23 Times in 23 Posts
    from:

    http://us4.php.net/filesize

    Code:
    <?PHP
    
    // outputs e.g.  somefile.txt: 1024 bytes
    
    $filename = 'somefile.txt';
    echo $filename . ': ' . filesize($filename) . ' bytes';
    
    ?>
    Lite...

  • #5
    Regular Coder
    Join Date
    Jul 2002
    Location
    Iran
    Posts
    695
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Did you notice this:

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


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •