www.webdeveloper.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 17

Thread: I can't upload my file with this PHP script. Why? Please help.

  1. #1
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    364

    I can't upload my file with this PHP script. Why? Please help.

    Ok, I'm bested. I found (and tailored) this PHP code to upload files I a specific location. It works for most files (JPGs, GIFs, TXTs), but I need it to upload mp4s. Whenever I do, it runs for a while, then throws an error. I think the file is getting half-uploaded, but not showing in my FTP (using WinSCP).

    I am not sure if there is a problem with the code or whatever, but it seems to execute the code just fine and finishes, but it gives me an error and doesn't display any text. The file also doesn't show in FTP.

    Any ideas why this could not be working?

    FYI, the file is about 12Mb.

    Thanks,
    Multi


    Code:
    if ($_FILES["file"]["size"] < 20000000)
      {
      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("videos/" . $_FILES["file"]["name"]))
          {
          echo $_FILES["file"]["name"] . " already exists. ";
          }
        else
          {
          move_uploaded_file($_FILES["file"]["tmp_name"],
          "videos/" . $_FILES["file"]["name"]);
          echo "Stored in: " . "videos/" . $_FILES["file"]["name"];
          }
        }
      }
    else
      {
      echo "Invalid file";
      }

  2. #2
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    364
    Any ideas?

  3. #3
    Join Date
    Sep 2008
    Posts
    408
    What's the max file size upload? ( phpinfo() for that). If it's a shared host many have the default 2mb limit.
    Mullanaphy!
    http://www.mullanaphy.com/

    Unless code is provided or an exact example is requested I think I'm going to start using psuedo code from now on...

    Also, I freelance as well. Inquire within!

  4. #4
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    364
    Good idea! But unfortunately, it's not the issue.

    Code:
    upload_max_filesize	20M
    Could this be anything else?

  5. #5
    Join Date
    Aug 2004
    Posts
    244
    What error does it give?

  6. #6
    Join Date
    Sep 2008
    Posts
    408
    Alrighty, how about the settings for:

    post_max_size - (Total size of uploads, should be alright there too)
    memory_limit - (This could be it, could be running out of memory, but if you have show errors and error_reporting(E_ALL) that would show)
    max_execution_time - (Could be timing out, if that's the case, set_time_limit(0); should take care of that).
    Mullanaphy!
    http://www.mullanaphy.com/

    Unless code is provided or an exact example is requested I think I'm going to start using psuedo code from now on...

    Also, I freelance as well. Inquire within!

  7. #7
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    364
    post_max_size - 8MB
    memory_limit - 40M
    max_execution_time - 50000

    Yep, this could be the problem. How (and where) do I change these settings?

    Thanks for all your help.

  8. #8
    Join Date
    Sep 2008
    Posts
    408
    If you have the ability, you could set it up in .htaccess.

    php_value post_max_size 32MB
    php_value memory_limit 128MB

    And the last one, use set_time_limit(0); on the page itself.

    However, if you are on a shared server changing those values via .htaccess can be blocked. If that's the case you would have to contact your hosting provider. If that's not the case and its your server you could also edit httpd.conf.
    Mullanaphy!
    http://www.mullanaphy.com/

    Unless code is provided or an exact example is requested I think I'm going to start using psuedo code from now on...

    Also, I freelance as well. Inquire within!

  9. #9
    Join Date
    Apr 2007
    Posts
    1,664
    No need to start another thread. I looked here too.

    Reply given here.
    http://www.webdeveloper.com/forum/sh...d.php?t=220472
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

  10. #10
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    364
    Ok, I'm taking a slightly different approach. I made a php.ini file for the directory. This should fix it. I added these variables, and I'm trying to upload a 12MB file.

    Code:
    upload_max_filesize = 10000M
    post_max_size = 10000M
    memory_limit = 120000M
    max_execution_time = 3000
    set_time_limit = 500000000
    After uploading (or attempting to upload), my script gives an error. Specifically, the $_FILES["file"]["error"] generates 2, meaning the file I'm uploading is larger than the allowed file size. Are there other variables I have to set?

  11. #11
    Join Date
    Sep 2008
    Posts
    408
    If it's inside the directory, .htaccess where you want to toss that stuff.

    Code:
    php_value max_execution_time 3000
    php_value upload_max_filesize 512M
    php_value post_max_size 512M
    php_value memory_limit 256M
    php_value set_time_limit 0
    Also, you might want to put that for only a single file with a file match, unless that's the only file in that directory.

    Not though, if on a shared host, the ability to change those variables via php or .htaccess can be blocked.
    Mullanaphy!
    http://www.mullanaphy.com/

    Unless code is provided or an exact example is requested I think I'm going to start using psuedo code from now on...

    Also, I freelance as well. Inquire within!

  12. #12
    Join Date
    May 2009
    Location
    Rochester, NY
    Posts
    364
    If it's inside the directory, .htaccess where you want to toss that stuff.

    Also, you might want to put that for only a single file with a file match, unless that's the only file in that directory.
    Hmm... I don't quite understand. Are you saying I should put an .htaccess file in my directory with these variables?

  13. #13
    Join Date
    Sep 2008
    Posts
    408
    Indeed,

    Open up .htaccess and add:
    Code:
      php_value max_execution_time 3000
      php_value upload_max_filesize 512M
      php_value post_max_size 512M
      php_value memory_limit 256M
      php_value set_time_limit 0
    However, if it's on a shared server then your hosting company can block the changing of these variables.
    Mullanaphy!
    http://www.mullanaphy.com/

    Unless code is provided or an exact example is requested I think I'm going to start using psuedo code from now on...

    Also, I freelance as well. Inquire within!

  14. #14
    Join Date
    Apr 2007
    Posts
    1,664
    Quote Originally Posted by multimediocrity View Post
    Hmm... I don't quite understand. Are you saying I should put an .htaccess file in my directory with these variables?
    multimediocrity, if you're going to ask the same questions in 2 threads, at least read them both. This was already answered in the other one.

    Shorts, don't forget when telling people to upload .htaccess file, they are not always visible by default in all ftp clients and file managers. If you create one and just upload it you may overwrite an existing file without knowing it.
    Anti Linux rants are usually the result of a lack of Linux experience, while anti Windows rants are usually a result of a lot of Windows experience.

  15. #15
    Join Date
    Sep 2008
    Posts
    408
    Good point. So used to utilizing .htaccess with FileZilla and ssh.

    From my guess though, those settings probably won't be able to be changed anyways. Would surmise that this is a shared server and changing those values is blocked.
    Mullanaphy!
    http://www.mullanaphy.com/

    Unless code is provided or an exact example is requested I think I'm going to start using psuedo code from now on...

    Also, I freelance as well. Inquire within!

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles