Results 1 to 3 of 3
  1. #1
    Join Date
    Mar 2006
    Posts
    41

    Unanswered: Uploading files using PHP

    Hi,

    I'm creating a website for my brothers band whereby the band have complete control over updating and editing the content. Part of the website is a music player which looks inside the folder called mp3 and loads all the mp3 files into the media player to be played.

    What I have is a method for the band to select a file from their computer to be uploaded to the folder named mp3. The only problem is that for some reason it returns error code 1 (which I think is file size exceeded) when I attempt to upload a file larger than about 2mb. I set size to 4000000 so they can upload files upto 4mb

    Here's the code, hopefully someone can help

    Code:
    <?php
    if (($_FILES["file"]["size"] < 4000000))
      {
      if ($_FILES["file"]["error"] > 0)
        {
        echo "Return Code: " . $_FILES["file"]["error"] . "<br />";
        }
      else
        {
        echo "Upload: " . $_FILES["file"]["name"] . "<br />";
        echo "Type: " . $_FILES["file"]["type"] . "<br />";
        echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
        echo "Temp file: " . $_FILES["file"]["tmp_name"] . "<br />";
    
        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 "Stored in: " . "mp3/" . $_FILES["file"]["name"];
          }
        }
      }
    else
      {
      echo "Invalid file";
      }
    ?>
    Also, is there a way I can make it so only mp3 files can be uploaded and not wav, midi etc.

    Cheers

  2. #2
    Join Date
    Apr 2006
    Location
    Denver, Co. USA
    Posts
    242
    From the PHP manual -
    Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini
    You can change this in php.ini or a .htaccess file. The value in the test in your code has no effect on what PHP is doing.

  3. #3
    Join Date
    Mar 2006
    Posts
    41
    Quote Originally Posted by dbmab
    From the PHP manual -
    You can change this in php.ini or a .htaccess file. The value in the test in your code has no effect on what PHP is doing.
    Is that something I would have to ask my webhost to do and are they likely to do it or not?

Posting Permissions

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