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

Thread: File Uploads

  1. #1
    New Coder
    Join Date
    Feb 2006
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    File Uploads

    Hi,

    I have a flash music player on my comapny intranet that plays files form a folder called "mp3".

    To allow employees upload their own music to this folder i created a form for them to do this:

    PHP Code:
    <form action="main.php" enctype="multipart/form-data" method="POST">
    <
    font class="style1">Add Music </font><input type="hidden" name="MAX_FILE_SIZE" value="9000000"><input type="file" name="userfile" id="userfile"><br><input type="submit" name="button" value="Submit"></form
    Now, to manage this i have the following code when submitted:

    PHP Code:
    $uploadDir 'mp3/';

    if (
    $userfile != ''){
        
    $fileName $_FILES['userfile']['name'];
        
    $tmpName  $_FILES['userfile']['tmp_name'];

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

    Now, my problem is, when i upload an .mp3 file, it doesnt work but if i upload any other file, it does. I can upload .wma files aand they work fine just not mp3!!

    Any ideas??

  • #2
    Master Coder mlseim's Avatar
    Join Date
    Jun 2003
    Location
    Cottage Grove, Minnesota
    Posts
    9,374
    Thanks
    8
    Thanked 1,075 Times in 1,066 Posts
    Your script does nothing with the Maximum size variable, but
    your webhost might ... I'm thinking your webhost has limited the
    maximum file size and you're seeing a situation where your MP3 file
    is larger than they allow, yet the other files you upload were within
    the limits.

    Ask your webhost what the maximum filesize is set to.
    Have them enlarge the default value to 10meg (or something like that).

  • #3
    New Coder
    Join Date
    Feb 2006
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for the reply,

    but that aint where my problem lies!! Im not using a webhost, this is on a local machine in the office that has a webserver installed on it (Apache, PHP, MySQL etc.) And i can upload any other files that are bigger than mp3s but it just wont upload mp3s!!

    Thanks again,

    Sully

  • #4
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    echo $filePath to see if its where you are wanting the mp3s to go.
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #5
    New Coder
    Join Date
    Jul 2007
    Location
    UK
    Posts
    36
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This is the code i have used to upload files:
    Code:
    <?php 
    if (($_FILES["file"]["type"] == "image/gif") 
    
    
    && ($_FILES["file"]["size"] < 20000)) 
    { 
      if ($_FILES["file"]["error"] > 0) 
        { 
        echo "Return Code: " . $_FILES["file"]["error"] . "<br />"; 
        } 
      else 
        {       
        if (file_exists("mp3/" . $_FILES["file"]["name"])) 
          { 
          echo $_FILES["file"]["name"] . " already exists. "; 
          } 
        else 
          { 
          move_uploaded_file($_FILES["file"]["tmp_name"], 
          "mp3/" . $_FILES["file"]["name"]); 
          echo  "You have successfully uploaded ". $_FILES["file"]["name"]; 
          } 
        } 
      } 
    else 
      { 
      echo "Invalid file"; 
      } 
    ?>
    But obviously you will change "image/gif" to whatever the mp3 file is, this works fine for me.
    http://www.smgames.staticfire.co.uk Under construction, Currently hiring mods and admins anyone interested pm me.


  •  

    Posting Permissions

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