help with this code

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    help with this code

    hi friends, i am not getting why am i getting this error when i try to upload files.. as all files are getting upload but may be larger files arent..but code shows some other problem than size.. i tried less than 2 mb, it got uploaded but higher than 2mb not getting upload.. really not understanding it. as filesize limit is also allot higher than 2 mb. help me .

    PHP Code:
    $time = date("d.m.Y, H:i:s");
    $Browser =  $_SERVER[HTTP_USER_AGENT];
    $ip=$_SERVER[REMOTE_ADDR];
    $desc=trim($_POST['desc']);
    $user=trim($_POST['user']);
    if(!$desc) $desc="No description available.";
    if(!$user) $user="Guest";
    // apare input-ul atata timp cat nu e Opera MIni 3.
    if (preg_match("/Opera Mini/i", $Browser) && !preg_match("/Opera Mini\/3.0/i", $Browser)) $OperaMini = TRUE;
    $no="no";

    header("Cache-Control: no-cache, must-revalidate");
    header("Content-type: text/html; charset=ISO-8859-1");
    echo "<?xml version=\"1.0\" encoding=\"ISO-8859-1\" ?>\n";
    echo "<!DOCTYPE html PUBLIC \"-//WAPFORUM//DTD XHTML Mobile 1.0//EN\"
    \"http://www.wapforum.org/DTD/xhtml-mobile10.dtd\">\n";
    echo "<html xmlns=\"http://www.w3.org/1999/xhtml\">\n";

    echo "<head>\n";
    include("config.php");

    echo "<title>Upload File</title>";
    echo "<link rel='stylesheet' href='style.css' type='text/css'/>";
    echo "</head>\n";
    echo "<body>";
    echo "<table bgcolor=\"#B0DBED\" width=\"100%\">";
    echo "<tr><td><font color='green' size='5'>Mobile</font><font color='blue' size='5'>Share</font></td></tr></table>";
    echo "<div class='hl'>Upload file</div>";

    if($_GET[page] !=="add"){
    echo "<form method=\"post\" enctype=\"multipart/form-data\" action=\"upload.php?page=add\">";
    if ($OperaMini) {
    echo "<input type='text' name='file1' size='30'/> <a href='op:fileselect'>Browse files</a><br>";
    }
    else {
    echo "<input type=\"file\" name=\"filetoupload\"><br>";
    }
    echo "<input type=\"Submit\" name=\"uploadform\" value=\"Upload File\">";
    echo "(max. <b>".$mb."</b> MB)</div>";
    echo "<div class=\"hl\">Optional</div>";
    echo "<div class=\"txt\"><b><font color=\"green\">User:</font></b>";
    echo "<br/><input type=\"text\" value=\"".$COOKIE["WapShareUser"]."\" name=\"user\" size=\"30\" /><br/>";
    echo "<div class=\"txt\"><b><font color=\"green\">Description:</font></b>";
    echo "<br/><textarea name=\"desc\" rows=\"4\" cols=\"40\"></textarea><br/>";
    echo "<small>Notice: once you submit the file, it will be available to public.</small>";
    echo "<br/><b>Please wait while the file is uploaded, it may take several minutes depending by the size of the file and by your internet bandwidth.</b>";
    echo "</div>";
    echo "</form>";

    }



    if ($_REQUEST[file1]) {
    $file1 = $_REQUEST[file1];
    $file1 = explode("=", $file1);
    $file_content = $file1[1];
    $filename = str_replace("file", "", $file1[0]);

    $size = strlen($file_content);


    }
    else {

    $filename = $_FILES['filetoupload']['name'];
    $size = $_FILES['filetoupload']['size'];
    }
    $ext = strrchr($filename,'.');
    $truext=str_replace(".","",$ext);
    $truext=strtolower($truext);
    $ext=strtolower($ext);
    $upload_dir=htmlspecialchars("$truext/");

    $filename=str_replace(" ","_",$filename);
    $filename=str_replace("`","",$filename);
    $filename=str_replace("]","",$filename);
    $filename=str_replace("[","",$filename);

    $filename=str_replace("~","",$filename);
    $filename=str_replace("@","",$filename);
    $filename=str_replace("#","",$filename);
    $filename=str_replace("%","",$filename);
    $filename=str_replace("^","",$filename);

    $filename=str_replace("*","",$filename);

    $filename=str_replace("|","",$filename);
    $filename=str_replace("$","",$filename);
    $filename=str_replace("&lt;","",$filename);
    $filename=str_replace("<","",$filename);
    $filename=str_replace(">","",$filename);
    $filename=str_replace("&gt;","",$filename);
    $filename=str_replace("\"","",$filename);
    $filename=str_replace("'","",$filename);
    $filename=str_replace("\\","",$filename);


    if($_GET['page']=="add"){

    if (!$filename)
    {
    echo "<b>Please select a file for upload.</b><br />";
    echo "<br /><div class='hl2'>";
    echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
    echo "<a href=\"index.php\"><b>[Menu]</b></a>";
    echo "<div><br />";
    echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
    die();
    }// i am getting this condition error. (please select a file for upload, but i already  selected file). and if i remove this condition then getting error downwards..


    if (($extlimit == "yes") && (in_array($ext,$limitedext)))
    {
    echo("Extension <b>$ext</b> was disabled due security reasons.The file was NOT uploaded!<br />");
    echo "<br />";
    echo "<br /><div class='hl2'>";
    echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
    echo "<a href=\"index.php\"><b>[Menu]</b></a>";
    echo "<div><br />";
    echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
    die();
    }


    if(strlen($filename)>$lungime_nume)
    {
    echo "<b><font color=\"red\">Your file name has a name too long.Please rename it!</font></b><br />";
    echo "<br /><div class='hl2'>";
    echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
    echo "<a href=\"index.php\"><b>[Menu]</b></a>";
    echo "<div><br />";
    echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
    die();
    }



    if ($size > $size_bytes)
    {
    echo "<b><font color=\"red\">Your file size is too big.Maximum allowed is $mb MB.</font></b><br />";
    echo "<br /><div class='hl2'>";
    echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
    echo "<a href=\"index.php\"><b>[Menu]</b></a>";
    echo "<div><br />";
    echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
    die();
    }


    if (file_exists("$upload_dir/$filename"))
    {
    echo("<b><font color=\"red\">File already exist.Please rename your file!</font></b><br />");
    echo "<br /><div class='hl2'>";
    echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
    echo "<a href=\"index.php\"><b>[Menu]</b></a>";
    echo "<div><br />";
    echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
    die();
    }

    if ($file1) {
    if(!is_dir($upload_dir)){mkdir($upload_dir); chmod($upload_dir,0777); copy("htaccess.txt","$upload_dir.htaccess");}

    $fp = fopen($upload_dir.$filename, "w") or die("File cannot be saved due server permissions");

    fwrite($fp, base64_decode($file_content));
    if (fclose($fp)) $Uploaded = TRUE;


    }
    else {
    if(!is_dir($upload_dir)){mkdir($upload_dir); chmod($upload_dir,0777); copy("htaccess.txt","$upload_dir.htaccess");}
    move_uploaded_file($_FILES['filetoupload']['tmp_name'], $upload_dir.$filename) or die("Cannot move uploaded file");// if remove upper condition than getting this die error. help me ..
    $Uploaded = TRUE;
    }

    if ($Uploaded)
    {
    mysql_query("INSERT INTO mobileshare (banned,file,user,browse,ip,ftype,uploaded,description,size) VALUES ('$no','$filename','$user','$Browser','$ip','$truext','$time','$desc','$size')");
    $sql = mysql_query("SELECT * FROM mobileshare WHERE file = '$filename' ");

    while($row = mysql_fetch_array($sql)){
    $id = $row['id'];}




    echo ("<b><font color=\"red\">Your file was uploaded </font><a href=\"file.php?id=$id\">here</a></b><br />
    <u>Copy and paste the following code:</u><br />
    <textarea name=\"link\" rows=\"5\" cols=\"40\">".$url."/file.php?id=".$id."</textarea><br />");

    echo "<br /><div class='hl2'>";
    echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
    echo "<a href=\"index.php\"><b>[Menu]</b></a>";
    echo "<div><br />";
    echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";

    die();
    }
    else
    {


    echo "<b><font color=\"red\">Unexpected error.Please try again.</font></b><br />";
    echo "<br />";
    echo "<br /><div class='hl2'>";
    echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
    echo "<a href=\"index.php\"><b>[Menu]</b></a>";
    echo "<div><br />";
    echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
    die();
    }


    }






    echo "<br /><div class='hl2'>";
    echo "<a href=\"upload.php\"><b>[Upload] </b></a>";
    echo "<a href=\"index.php\"><b>[Menu]</b></a>";
    echo "<div><br />";
    echo "<table bgcolor=\"B0DBED\" width=\"100%\"><tr><td>Powered by <a href=\"$homepage_url\">$admin</a></td></tr></table>";
    echo "</body>";
    echo "</html>";
    and also, can somebody add url upload feature to this script? hmm, i will also try to do with new sql row.

    please solve error for me as i liked this uploader for my site. thank you in advance!!
    Attached Files
    Last edited by icedroplet1987; 29.03.12, 19:45.

    #2
    is this uploading problem by opera mini or is it on other browsers?

    Also i would recommend having a strong .htaccess as the uploader is insecure

    Comment


      #3
      are you using a free host?

      run this code

      PHP Code:
      <?php
      echo ini_get('upload_max_filesize');
      ?>
      I need some facebook likes, can you please help me
      http://facebook.com/softwarefreakin
      I noticed social media is really powerful
      Well DONE is better than well SAID

      Comment


        #4
        i would probably try changing line 10 on upload.php to:
        PHP Code:
        if (preg_match("/Opera Mini/i"$Browser) && !preg_match("/Opera Mini\/3.0/i"$Browser)) $OperaMini TRUE; else $OperaMini FALSE

        Comment


          #5
          well thanks about htac , as i already worked on that and the problem is with all browsers as tested with firefox, opera, ID and chrome.. hmm, yup php ini maxfilesize might work. let me check out.

          thanks to having a look

          Originally posted by softwarefreak View Post
          are you using a free host?

          run this code

          PHP Code:
          <?php
          echo ini_get('upload_max_filesize');
          ?>
          nope, i am not on a free host but perhaps this will help.

          Added after 9 minutes:

          nope it did not worked .
          Last edited by icedroplet1987; 29.03.12, 20:39.

          Comment


            #6
            Add this to line 139:
            PHP Code:
            echo "Debug: Size=".$size." Size_Bytes=".$size_bytes."<br/>"
            and upload a file and see what it tells you the values are

            Comment


              #7
              wat you mean?did not work? :D

              what did you see when the code executed?
              I need some facebook likes, can you please help me
              http://facebook.com/softwarefreakin
              I noticed social media is really powerful
              Well DONE is better than well SAID

              Comment


                #8
                re

                some hosts set a filesize limit on uploaders.?if i were u id look at your hosts t & cs as i think this is your problem they set the upload limit on your account









                Dont Ask Me Dumb Questions.Or you'l get a Dumb Answer..
                Want A Profesional Logo or Theme For Your wap site Pm Me.If I Have The Time Ill Make It For Free

                Comment


                  #9
                  Originally posted by ozziemale31 View Post
                  are you using paid host or free host some hosts set a filesize limit on uploaders.?
                  well, i already mentioned it. i am on a paid host. and its a master reseller, i do not have any restrictions with host as i also tried it on localhost but problem is same. its giving me max filesize limit 2M.. 2MB even i changed size limit in configuration file.

                  i am not getting file size error, i am getting the other ones which i mentioned in my topic .
                  Last edited by icedroplet1987; 31.03.12, 22:20.

                  Comment


                    #10
                    friends, i am again facing the same problem and when i checked the max filesize limit with something else code, its giving me 2M .. i tried to change it via php.ini but its not working for me. can anyone download this script and solve my problem ?? please help!!


                    check the code please, i mentioned where am i getting error.

                    actually, error logs telling "Line 1: [30-Mar-2012 22:47:45 UTC] PHP Warning: POST Content-Length of 22919596 bytes exceeds the limit of 8388608 bytes in Unknown on line 0" but i am not able to find the limit defined anywhere as 8388608 bytes. its frustrating!!
                    Last edited by icedroplet1987; 31.03.12, 22:59.

                    Comment


                      #11
                      Recode it, try to remove Opera Mini from the form and retrieve file just with $_FILE.
                      <!DOCTYPE html PUBLIC "-//WAPFORUM.RS

                      Comment


                        #12
                        Originally posted by icedroplet1987 View Post
                        friends, i am again facing the same problem and when i checked the max filesize limit with something else code, its giving me 2M .. i tried to change it via php.ini but its not working for me. can anyone download this script and solve my problem ?? please help!!


                        check the code please, i mentioned where am i getting error.

                        actually, error logs telling "Line 1: [30-Mar-2012 22:47:45 UTC] PHP Warning: POST Content-Length of 22919596 bytes exceeds the limit of 8388608 bytes in Unknown on line 0" but i am not able to find the limit defined anywhere as 8388608 bytes. its frustrating!!
                        in php.ini edit the following
                        post_max_size = 16M
                        upload_max_filesize = 16M
                        memory_limit = 16M

                        and replace 16M with the number you require, then restart apache

                        Comment


                          #13
                          thanks

                          i already did it @ am but somewhere limit is also defined in script.

                          hmm, okay i will try @ arnage

                          Comment


                            #14
                            you can use:
                            .htaccess
                            PHP Code:
                            php_value upload_max_filesize 8M 
                            php_value post_max_size 8M 
                            I think you can also use this in your script:
                            PHP Code:
                            ini_set('max_upload_filesize'8388608);
                            ini_set('post_max_size'8388608); 

                            if you need to find out the size limits use
                            PHP Code:
                            echo "Max upload size: ".ini_get('max_upload_filesize')."<br/>";
                            echo 
                            "Max post size: ".ini_get('post_max_size')."<br/>"
                            Added after 4 minutes:

                            Originally posted by arnage View Post
                            Recode it, try to remove Opera Mini from the form and retrieve file just with $_FILE.
                            I thought it was same thing to begin with but the error is line 0 , meaning its not a script problem
                            Last edited by something else; 01.04.12, 08:29.

                            Comment


                              #15
                              Decoded config file & modded .. .

                              PHP Code:
                              <?php
                              //START CONFIGURATION
                              $lungime_nume 80;//max length name of a file
                              $size_bytes 52428800//max size,in bytes 50MB set
                              $extlimit "yes";//allow all extensions?("yes" OR "no")
                              $limitedext = array(".htm",".html",".cgi",".pl",".m3u",".php",".wml");//list with banned extensions,with "DOT" and in lowercase
                              $db_host "localhost";  // DB Host
                              $db_user "";  // DB User
                              $db_pass "";  // DB Pass
                              $db_name "sharere";  // DB Name
                              $sitename "sharemobile";
                              $url="http://plm.plta/up";//Full URL to your folder,no trailing slash
                              //END CONFIGURATION
                              $dbc = @mysql_connect($db_host$db_user$db_pass) or die(mysql_error());
                              $dbs = @mysql_select_db($db_name) or die(mysql_error());
                              $kb $size_bytes 1024;
                              $mb $size_bytes 1024000;
                              if(
                              file_exists("remove.php")) include("remove.php");
                              $homepage_url="http://".$_SERVER['HTTP_HOST']."";
                              $admin="admin";

                              ?>



                              php.ini content


                              Code:
                              [PHP]
                              register_globals = Off
                              file_uploads = On
                              safe_mode = off
                              open_basedir =
                              output_buffering = on
                              upload_max_filesize = 50M
                              post_max_size = 50M
                              memory_limit = 32M
                              max_execution_time = 6000 
                              max_input_time = 6000
                              try and reply ... okay ? i had same problem that php.ini fixed it ..
                              This is ten percent luck, twenty percent skill
                              Fifteen percent concentrated power of will
                              Five percent pleasure, fifty percent pain

                              And a hundred percent reason to remember the name!

                              Comment

                              Working...
                              X