Jump to content

Problem with uploading huge files


ra_ie_darkness

Recommended Posts

I'm trying to create a function to upload files on my server

It is working fine but the problem is that it doesn't work when I try to upload files larger than 15/20 mb

function uploadfile()
    {
        global $id;
        $getid = mysql_query("Select * from user where email='$id'");
        while($result = mysql_fetch_array($getid))
        {
            $userid = $result['id'];
        }        
        $dir = "C:\\xampp\\htdocs\\filehost\\";
        $dir.=$userid."\\";
        if($_FILES['usr']['size']>2097152) //2megabytes
        {
           echo "You cannot upload files greater than 2mb";
        }       
        else
        {
            if(move_uploaded_file($_FILES['usr']['tmp_name'],$dir.$_FILES['usr']['name']))
            {
                $fname = mysql_real_escape_string($_FILES['usr']['name']);
                $fsize = $_FILES['usr']['size'];
                $date = date("Y-m-d");
                $dlurl = substr(md5(uniqid()), 0,10);
                $newdir = mysql_real_escape_string($dir);
                $fquery = mysql_query("SELECT * from folder where name ='$userid'");
                while($row = mysql_fetch_array($fquery))
                {
                    $folderid = $row['name'];
                }
                echo "File uploaded";
                if(!mysql_query("INSERT INTO myfile (fileid,userid,fid,name,size,date,location,dlurl) VALUES ('','$userid','$folderid','$fname','$fsize','$date','$newdir','$dlurl')"))
                {
                    echo "Identify";
                }
                else
                {
                    echo "File uploaded";
                }
                
            }
        }
               
            //echo "File moved";
    }

 

I have given a condition which does not allow files larger than 2 mb but instead of getting the message "You cannot upload files greater than 2mb" I get php error messages

 

How can I fix this

 

Link to comment
Share on other sites

Your ini is probably not allowing you to upload super-large files.

 

This will allow large file upload, but not advisable:

 

ini_set("upload_max_filesize", "10M");

ini_set("post_max_size", "10M");

 

In fact, you should probably restrict the file size in the browser to prevent bandwidth hogging.

Link to comment
Share on other sites

You cannot set the upload size limits using ini_set statements in a script. Php uses those values before it ever invokes a script. You must set them in the master php.ini (when you have access to it), in a local php.ini (when php is running as a cgi application), or in a .htaccess file (when php is running as an Apache Module.) You would also NEED to set them to larger values if you are using php to process uploaded files, so it would be very advisable to change the php settings.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.