Başlıkları> olduğunda $ _POST verileri boş döner

4 Cevap

Umarım burada birisi benim soruya bir cevap olabilir.

Ben adı, numarası, e-posta adresi vb ve 1 dosya yükleme alanı gibi basit alanları içeren bir temel form var.

Ben dosya çok büyük ve sonra tekrar küçük bir dosya yüklemek / seçmek için forma kullanıcı reddederse algılar benim komut dosyası içine bazı doğrulama eklemek çalışıyorum.

Bir kullanıcı php.ini post_max_size / upload_max_filesize daha benim geçerlilik dosya boyutu kural daha büyük ve daha büyük ve daha sonra PHP sadece o post_max_size ayarları ve vernikler üzerinde başarısız işlemek formu denemek görünüyor, teslim iten bir dosyayı seçerse Benim sorun, geri formuna tüm $ _POST dizi ve döner bir şey.

Bu etrafında bir yolu var mı? Birisi php.ini yapılandırılan azami boyuttan şey> yükler Şüphesiz eğer hala $ _POST verilerin geri kalanını alabilirim??

İşte benim kodudur.

<?php

   function validEmail($email)
    {
       $isValid = true;
       $atIndex = strrpos($email, "@");
       if (is_bool($atIndex) && !$atIndex)
       {
          $isValid = false;
       } else {
          $domain = substr($email, $atIndex+1);
          $local = substr($email, 0, $atIndex);
          $localLen = strlen($local);
          $domainLen = strlen($domain);

          if ($localLen < 1 || $localLen > 64)
          {
             // local part length exceeded
             $isValid = false;
          }
          else if ($domainLen < 1 || $domainLen > 255)
          {
             // domain part length exceeded
             $isValid = false;
          }
          else if ($local[0] == '.' || $local[$localLen-1] == '.')
          {
             // local part starts or ends with '.'
             $isValid = false;
          }
          else if (preg_match('/\\.\\./', $local))
          {
             // local part has two consecutive dots
             $isValid = false;
          }
          else if (!preg_match('/^[A-Za-z0-9\\-\\.]+$/', $domain))
          {
             // character not valid in domain part
             $isValid = false;
          }
          else if (preg_match('/\\.\\./', $domain))
          {
             // domain part has two consecutive dots
             $isValid = false;
          }
          else if
          (!preg_match('/^(\\\\.|[A-Za-z0-9!#%&`_=\\/$\'*+?^{}|~.-])+$/', str_replace("\\\\","",$local)))
          {
             // character not valid in local part unless 
             // local part is quoted
             if (!preg_match('/^"(\\\\"|[^"])+"$/', str_replace("\\\\","",$local)))
             {
                $isValid = false;
             }
          }

       }
       return $isValid;
    }

        //setup post variables
        @$name = htmlspecialchars(trim($_REQUEST['name'])); 
        @$emailCheck = htmlspecialchars(trim($_REQUEST['email']));
        @$organisation = htmlspecialchars(trim($_REQUEST['organisation']));
        @$title = htmlspecialchars(trim($_REQUEST['title']));
        @$phone = htmlspecialchars(trim($_REQUEST['phone']));
        @$location = htmlspecialchars(trim($_REQUEST['location']));
        @$description = htmlspecialchars(trim($_REQUEST['description']));
        @$fileError = 0;
        @$phoneError = "";

        //setup file upload handler
        $target_path = 'uploads/';
        $filename =  basename( @$_FILES['uploadedfile']['name']);
        $max_size = 8000000; // maximum file size (8mb in bytes) NB: php.ini max filesize upload is 10MB on test environment.
        $allowed_filetypes = Array(".pdf", ".doc", ".zip", ".txt", ".xls", ".docx", ".csv", ".rtf"); //put extensions in here that should be uploaded only.
        $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.

        if(!is_writable($target_path)) die('You cannot upload to the specified directory, please CHMOD it to 777.'); //Check if we can upload to the specified upload folder.


        //display form function
        function displayForm($name, $emailCheck, $organisation, $phone, $title, $location, $description, $phoneError, $allowed_filetypes, $ext, $filename, $fileError)
        {
          //make $emailCheck global so function can get value from global scope.
          global $emailCheck;
          global $max_size;



          echo  '<form action="geodetic_form.php" method="post" name="contact" id="contact" enctype="multipart/form-data">'."\n".
                '<fieldset>'."\n".'<div>'."\n";

          //name        
          echo '<label for="name"><span class="mandatory">*</span>Your name:</label>'."\n".
                '<input type="text" name="name" id="name" class="inputText required" value="'. $name .'" />'."\n";

                //check if name field is filled out
                if (isset($_REQUEST['submit']) && empty($name)) 
                {        
                  echo '<label for="name" class="error">Please enter your name.</label>'."\n";
                }

           echo '</div>'."\n". '<div>'."\n";

           //Email     
           echo '<label for="email"><span class="mandatory">*</span>Your email:</label>'."\n".
                '<input type="text" name="email" id="email" class="inputText required email" value="'. $emailCheck .'" />'."\n";

               // check if email field is filled out and proper format   
                if (isset($_REQUEST['submit']) && validEmail($emailCheck) == false)
                {
                  echo '<label for="email" class="error">Invalid email address entered.</label>'."\n";
                }

           echo '</div>'."\n". '<div>'."\n";

           //organisation     
           echo '<label for="phone">Organisation:</label>'."\n".
                '<input type="text" name="organisation" id="organisation" class="inputText" value="'. $organisation .'" />'."\n";
           echo '</div>'."\n". '</fieldset>'."\n".'<fieldset>'. "\n" . '<div>'."\n";

           //title     
           echo '<label for="phone">Title:</label>'."\n".
                '<input type="text" name="title" id="title" class="inputText" value="'. $title .'" />'."\n";        
           echo '</div>'."\n". '</fieldset>'."\n".'<fieldset>'. "\n" . '<div>'."\n";

          //phone     
           echo '<label for="phone"><span class="mandatory">*</span>Phone <br /><span class="small">(include area code)</span>:</label>'."\n".
                '<input type="text" name="phone" id="phone" class="inputText required" value="'. $phone .'" />'."\n";       

           // check if phone field is filled out that it has numbers and not characters
           if (isset($_REQUEST['submit']) && $phoneError == "true" && empty($phone)) echo '<label for="email" class="error">Please enter a valid phone number.</label>'."\n";       

           echo '</div>'."\n". '</fieldset>'."\n".'<fieldset>'. "\n" . '<div>'."\n";

            //Location     
            echo '<label class="location" for="location"><span class="mandatory">*</span>Location:</label>'."\n".
                 '<textarea name="location" id="location" class="required">'. $location .'</textarea>'."\n";

            //check if message field is filled out
            if (isset($_REQUEST['submit']) && empty($_REQUEST['location'])) echo '<label for="location" class="error">This field is required.</label>'."\n";

            echo '</div>'."\n". '</fieldset>'."\n".'<fieldset>'. "\n" . '<div>'."\n";

           //description     
           echo '<label class="description" for="description">Description:</label>'."\n".
                '<textarea name="description" id="queryComments">'. $description .'</textarea>'."\n";               
           echo '</div>'."\n". '</fieldset>'."\n".'<fieldset>'. "\n" . '<div>'."\n";

          //file upload
           echo '<label class="uploadedfile" for="uploadedfile">File:</label>'."\n".
                '<input type="file" name="uploadedfile" id="uploadedfile" value="'. $filename .'" />'."\n";

           // Check if the filetype is allowed, if not DIE and inform the user.   
           switch ($fileError)
           {
            case "1":
                echo '<label for="uploadedfile" class="error">The file you attempted to upload is not allowed.</label>';
            break;

            case "2":
                echo '<label for="uploadedfile" class="error">The file you attempted to upload is too large.</label>';
            break;
           }   
           echo '</div>'."\n". '</fieldset>';

            //end of form
            echo '<div class="submit"><input type="submit" name="submit" value="Submit" id="submit"  /></div>'.
                 '<div class="clear"><p><br /></p></div>';
        } //end function

        //setup error validations
        if (isset($_REQUEST['submit']) && !empty($_REQUEST['phone']) && !is_numeric($_REQUEST['phone'])) $phoneError = "true";
        if (isset($_REQUEST['submit']) && $_FILES['uploadedfile']['error'] != 4 && !in_array($ext, $allowed_filetypes)) $fileError = 1;
        if (isset($_REQUEST['submit']) && $_FILES["uploadedfile"]["size"] > $max_size) $fileError = 2; echo "this condition " . $fileError; 

        $POST_MAX_SIZE = ini_get('post_max_size');
        $mul = substr($POST_MAX_SIZE, -1);

        $mul = ($mul == 'M' ? 1048576 : ($mul == 'K' ? 1024 : ($mul == 'G' ? 1073741824 : 1)));
        if ($_SERVER['CONTENT_LENGTH'] > $mul*(int)$POST_MAX_SIZE && $POST_MAX_SIZE) echo "too big!!";
        echo $POST_MAX_SIZE;


        if(empty($name) || empty($phone) || empty($location) || validEmail($emailCheck) == false || $phoneError == "true" || $fileError != 0)
        {
            displayForm($name, $emailCheck, $organisation, $phone, $title, $location, $description, $phoneError, $allowed_filetypes, $ext, $filename, $fileError);
          echo $fileError;
          echo "max size is: " .$max_size;
          echo "and file size is: " .  $_FILES["uploadedfile"]["size"];
          exit;
        } else {

            //copy file from temp to upload directory
            $path_of_uploaded_file = $target_path . $filename;
            $tmp_path = $_FILES["uploadedfile"]["tmp_name"];
            echo $tmp_path;
            echo "and file size is: " .  filesize($_FILES["uploadedfile"]["tmp_name"]);
            exit;
            if(is_uploaded_file($tmp_path))
            {
              if(!copy($tmp_path,$path_of_uploaded_file))
              {
                echo 'error while copying the uploaded file';
              }
            }

        //test debug stuff
            echo "sending email...";
            exit;


        }
        ?>

PHP is returning this error in the log: [29-Apr-2010 10:32:47] PHP Warning: POST Content-Length of 57885895 bytes exceeds the limit of 10485760 bytes in Unknown on line 0

Tüm hata ayıklama şeyler dilerim :)

FTR, IIS üzerinde PHP 5.1.2 çalıştırıyorum.

4 Cevap

Koymak için hiçbir yer yoktu çünkü PHP uzakta tüm POST verileri atar. Verilerin sadece parçası olduğu için güvenilir bir şey yok.

Ben ayrı bir aşamada farklı bir formda gerekli dosyaları yükleyerek bu soruna olacaktır. Onların yüzünden aşırı POST veri kaybı olmayan sağlanması, zaten oturumda elde değerlerini saklayabilirsiniz.

Erisco doğru, bu çoklu adımlara bölünebilir gerekecektir. Ben kullanıcıya bu arka-uç nitelendirmesini maruz herhangi bir ihtiyaç olduğunu, ancak, inanmıyorum, bu yüzden eylem aşağıdaki derslerden birini öneriyoruz:

Ayrı bir <form> elemanın içine dosya yükleme kırın. Göndermek eylem ya formda alındığında, varsayılan eylemi iptal etmek ve onun yerine iki şeyden birini yapın:

  1. AJAX ile normal form verilerini göndermek, ve o zaman tam bir standart işlemi yoluyla yüklenen dosyayı göndermek (sayfa yeniden yükleme içeren ve ne değildir)
  2. this example of iFrame trickery, ilk dosya upload çok büyük değil emin olun, ve aksi geçmek olmaz bile yeniden gelen sayfası önlemek için check out. Dosya geçmek yaparsa, gizli bir giriş elemanı onun tanımlayıcı depolamak ve normal formu gönderin. Dosya düzgün karşıya değilse uygun olup her türlü tedbiri alacaktır. Bu çözüm, yanıt hile sadece biraz PHP oturumu kullanmak gerekmez unutmayın.

Eğer _POST dizi nuke olmuştur bulduktan sonra php://input veya php://stdin bir şey okuyabilir görmesini deneyebilirsiniz. Siz form {[(4)] kullanarak bu //input için işe yaramaz olduğunu manuel also says oradan POST veri almak ve elle işlemek mümkün olabilir, ancak }

hileler biri böyle bir şey kullanmak için:

$lE = error_get_last();
if (  !empty($lE) &&  strpos($lE['message'] , 'POST Content-Length' ) !== false)
{
 die ('Naughty naughty.  you can only upload xxxxx bytes');
}