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 2008
    Posts
    119
    Thanks
    23
    Thanked 2 Times in 2 Posts

    Upload script questions

    I've been playing around with this upload script.
    It seems to work fine for the smaller img formats, but not for mp3 files.
    I don't know if it's a file type or file size problem.
    It appears to upload the mp3, but no link is given and the mp3 is not in the upload directory.

    Edit: Or maybe it could be a timeout problem. I don't know.

    And another thing I need fixing is the link display.
    If you upload a file with spaces in the title, the link shows the spaces.
    I need it to actually print the url to the file.
    PHP Code:
    echo "Link: " "http://mydomain.com/upload/files/" $_FILES["file"]["name"]; 
    Here is the script, if anyone can lend a hand.
    PHP Code:
    <form action="upload.php" method="post"
    enctype="multipart/form-data">
    <label for="file">Filename:</label>
    <input type="file" name="file" id="file" /> 
    <br /><br />
    <input type="submit" name="submit" onclick="showIcon();" value="Submit" /><br /><br />
    <div class="progress" id="progressImg">&nbsp;
    <img src="http://mydomain.com/upload/progress.gif" alt="Uploading" />
    </div>
    </form>
    <br />
    <?php
    if ((($_FILES["file"]["type"] == "image/gif")
    || (
    $_FILES["file"]["type"] == "image/jpeg")
    || (
    $_FILES["file"]["type"] == "image/png")
    || (
    $_FILES["file"]["type"] == "audio/mpeg3")
    || (
    $_FILES["file"]["type"] == "application/x-shockwave-flash")
    || (
    $_FILES["file"]["type"] == "image/pjpeg"))
    && (
    $_FILES["file"]["size"] < 10485760))
      {
      if (
    $_FILES["file"]["error"] > 0)
        {
        echo 
    "Return Code: " $_FILES["file"]["error"] . "<br />";
        }
      else
        {

        if (
    file_exists("files/" $_FILES["file"]["name"]))
          {
          echo 
    $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
          
    move_uploaded_file($_FILES["file"]["tmp_name"],
          
    "files/" $_FILES["file"]["name"]);
          echo 
    "Link: " "http://mydomain.com/upload/files/" $_FILES["file"]["name"];
          }
        }
      }
    else
      {
      echo 
    "Invalid file";
      }
    ?>
    Last edited by Jedi Knight; 12-11-2008 at 11:49 PM. Reason: Resolved

  • #2
    Regular Coder
    Join Date
    Dec 2006
    Location
    In the wilderness
    Posts
    106
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Depends on how big the mp3 file is, PHP has 16MB set as default for file uploads, you may need to change this in the PHP.INI file. First check out by running phpinfo(). Open a new php file and enter this:

    PHP Code:
    <?php phpinfo(); ?>
    What you need to looks for and possibly change is:

    post_max_size (16MB by default) make this slightly higher than upload_max_filesize so it can submit the form info, if required.
    upload_max_filesize (also 16MB by default)
    max_execution_time (60 seconds by default, might need to make this higher to stop timing out errors)
    "The advantage of computers is that they do exactly what you tell them to do. The disadvantage of computers, on the other hand, is that they do exactly what you tell them to do."

    Excellent resource for learning PHP here

  • Users who have thanked karlosio for this post:

    Jedi Knight (12-11-2008)

  • #3
    Regular Coder
    Join Date
    Feb 2008
    Posts
    119
    Thanks
    23
    Thanked 2 Times in 2 Posts
    My 'upload max filesize' 24MB
    My 'post max size' 32MB
    But my 'max execution time' is only 60

    I don't think I have access to change this.
    I'll have to get with my host and see if I can get it changed.
    But that probable is my problem, as I'm on a slow connection when it comes to uploading.

    Thanks for your great help.
    Do you have any ideas about the second problem I mentioned above?


    After doing some reading, I am wondering if an alternate course may be taken.
    Instead of trying to get my php.ini file edited (not very likely), can the 'max execution time' by altered with .htaccess, or this code:
    PHP Code:
    <? ini_set("session.gc_maxexecutiontime","180"); ?>
    Last edited by Jedi Knight; 12-11-2008 at 07:48 AM.

  • #4
    Regular Coder
    Join Date
    Feb 2008
    Posts
    119
    Thanks
    23
    Thanked 2 Times in 2 Posts
    I'm beginning to think it is not a timeout problem.
    I just converted a mp3 file down to 413KB and it still won't upload it.
    I've uploaded larger image files than 413KB.
    So it must be the mime type.

    Does anyone see anything wrong with the code above.
    Particularly this part:
    PHP Code:
    if ((($_FILES["file"]["type"] == "image/gif")
    || (
    $_FILES["file"]["type"] == "image/jpeg")
    || (
    $_FILES["file"]["type"] == "image/png")
    || (
    $_FILES["file"]["type"] == "audio/mpeg3")
    || (
    $_FILES["file"]["type"] == "application/x-shockwave-flash")
    || (
    $_FILES["file"]["type"] == "image/pjpeg"))
    && (
    $_FILES["file"]["size"] < 10485760)) 
    Should
    PHP Code:
    || ($_FILES["file"]["type"] == "audio/mpeg3"
    Be this instead
    PHP Code:
    || ($_FILES["file"]["type"] == "audio/mp3"
    I finally got it to work by adding the following:
    PHP Code:
    || ($_FILES["file"]["type"] == "audio/mpeg")
    || (
    $_FILES["file"]["type"] == "audio/x-mpeg")
    || (
    $_FILES["file"]["type"] == "aaudio/mp3")
    || (
    $_FILES["file"]["type"] == "audio/x-mp3")
    || (
    $_FILES["file"]["type"] == "audio/mpeg3")
    || (
    $_FILES["file"]["type"] == "audio/mpg")
    || (
    $_FILES["file"]["type"] == "audio/x-mpg")
    || (
    $_FILES["file"]["type"] == "audio/x-mpegaudio"
    I'm sure that this may be redundant, but not knowing which one is correct, I'll just leave all of them in there.

    Now if I can get the link to display correctly, I can mark this thread as solved.
    Would str_replace fix this, and if so, can someone post an example?
    Last edited by Jedi Knight; 12-11-2008 at 04:27 PM.

  • #5
    Regular Coder
    Join Date
    Feb 2008
    Posts
    119
    Thanks
    23
    Thanked 2 Times in 2 Posts
    I used urlencode and urldecode and got it working the way I want it. Thanks for helping.


  •  

    Posting Permissions

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