SitePoint Sponsor

User Tag List

Results 1 to 5 of 5

Thread: Upload error

  1. #1
    SitePoint Enthusiast PeteWJ's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Upload error

    Hi,

    First post on this forum - I'm an ASP programmer generally but have recently been working in PHP to build a site for a production company (host restrictions )

    They require a section for customers to upload MP3 files and, with a lot of hacking, came up with this (very basic ) code.
    PHP Code:
    <?php
    $uploaddir 
    "/home/******/***/upload/uploads"// asterisks added for this post!
    $final_filename $imgfile_name;

    $newfile $uploaddir "/" $final_filename;
    if (!
    copy($imgfile$newfile)) {
      
    // Flag error
    }
    else
    {
      
    // Redirect to confirmation page
    }
    ?>
    The problem I am having isn't that the script isn't working at all - instead it is working up to certain upload time lengths and then returning Warning: Unable to open 'none' for reading: No such file or directory in /home/pbdotcom/productionbloke-www/upload/upload.php on line 7
    I have done some tests and it certainly seems time related. Both a cable modem and 56K dial-up can upload 500KB files no problems. The dial-up returns the above error on files anything larger than 1.4MB (ish - depends on the speed of connection) and the cable modem chokes at about 7MB.
    Are there some timeout issues that I am not aware of or am I doing something stupid (which is likely )
    If required, here is my calling HTML:
    Code:
    <form method="POST" action="upload.php" enctype="multipart/form-data">
      <input type="file" name="imgfile" size="30"><br><br>
      <input type="submit" value="UPLOAD">
    </form>
    Thanks guys - hope someone can shed some light.

    Pete

  2. #2
    SitePoint Addict whofarted's Avatar
    Join Date
    Aug 2001
    Location
    lost, If you find me please return me to St.Louis
    Posts
    396
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not posative about this but you might wanna check your php.ini file.

    Check the settings for timout & max file upload size. That would be one place to start.

    **edit**

    Also try something like this (i'm still learning php to but I think this has something to do with it)

    PHP Code:
    if ($userfile AND $userfile != "none")

    //your code here

    Hope this somehow helps
    Last edited by whofarted; May 4, 2002 at 05:41.
    You smell something?

  3. #3
    SitePoint Enthusiast PeteWJ's Avatar
    Join Date
    Oct 2001
    Location
    UK
    Posts
    75
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thanks for your help. It turned out to be the upload_max_filesize value in the php.ini file. I don't know how the 7MB file got through and my hosting company is currently looking at the logs to try and work it out.

    Ah well, I added the change to the .htaccess file and am now uploading files happily (although what my bandwidth account will look like this month I would hate to think )

    Thanks again,

    Pete

  4. #4
    Making a better wheel silver trophy DR_LaRRY_PEpPeR's Avatar
    Join Date
    Jul 2001
    Location
    Missouri
    Posts
    3,428
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    i would write the code like this. not using global variables (your code won't work eventually if you use them; guaranteed ), and using move_uploaded_file() instead of copy() since this is what move_uploaded_file() is for.

    PHP Code:
    <?php

    $uploaddir 
    '/home/******/***/upload/uploads'// asterisks added for this post!
    $final_filename $_FILES['imgfile']['name'];

    $newfile $uploaddir '/' $final_filename;

    // See if a file was uploaded
    if ($_FILES['imgfile']['tmp_name'] == '' || $_FILES['imgfile']['tmp_name'] == 'none')
    {
        
    // No file, if you want to do something here
    }

    if (!
    move_uploaded_file($_FILES['imgfile']['tmp_name'], $newfile))
    {
        
    // Flag error
    }
    else
    {
        
    // Redirect to confirmation page
    }

    ?>
    note: if your version of PHP is less than 4.1.0, change $_FILES to $HTTP_POST_FILES.
    - Matt ** Ignore old signature for now... **
    Dr.BB - Highly optimized to be 2-3x faster than the "Big 3."
    "Do not enclose numeric values in quotes -- that is very non-standard and will only work on MySQL." - MattR

  5. #5
    SitePoint Addict exhale81's Avatar
    Join Date
    Aug 2001
    Location
    Switzerland
    Posts
    395
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Uploading files above 5Mb can be really difficult depending on the version of PHP you use (since you've had a timeout, I'd assume you use 4.2). Check this thread for details:

    http://www.sitepointforums.com/showt...threadid=50669
    Sebastien Rosset
    :: Commercial: BlackSonic | ScriptsCenter
    :: Non-Profit: VJCentral | ReclaimYourSoul


Bookmarks

Posting Permissions

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