HTML表单只是不会将一些POST变量发送到PHP脚本

时间:2015-01-24 15:39:49

标签: php html forms variables

所以我遇到了一个问题,导致我无法将文件作为测试上传到我的新上传服务中。

每当我正确填写每个表格并提交它时,就不会为up-loader设置一堆变量。

HTML表单(从我的网站剪切,我留下了一些引导元素以防万一):

<form action="upload.php" method="post">
            <span style="color: green;">Select the file you want to upload:</span>
            <input type="file" class="form-control" name="fileToUpload" id="fileToUpload" />
            <br>TIP: Taking a long time for the page to load after uploading? That's your browser uploading the files. It will take time if you have slow internet or you are uploading a big file.
            <br><br>
            <b><span style="color: red;">DISCLAIMER: I, Mark Jones, am not held responsible for the uploading of porn, pirated music, images and films. In the event that any pirated, offensive or sexual files are uploaded they will be deleted by staff or removed by storage clean-ups. Please keep all these types of files that are not permitted away from this website. Only upload things that are not sold elsewhere and keep porn on your own PC. Once you upload a file against this disclaimer after accepting it (You can't upload files without accepting it), The uploaded file becomes your responsibility. It will be deleted and if it is not deleted then you'll have to witness a punishment that hasn't been put into effect by me, but by others such as my hosting or the DMCA. I also would like all the members/users of this site not to upload Viruses, Tojans, Malware and Spyware. If you do, It will be deleted or other punishments will occur. Also by accepting this disclaimer you must use your real name in the box below.</span></b><br><br>
            <!--<input type="submit" value="Upload Image" name="submit" />-->
            <input type="radio" name="disclaimer" value="1">Accept</input>
            <input type="radio" name="disclaimer" value="0" checked>Decline</input><br><br>
            Insert your full real name below:<br>
            <input type="text" class="form-control" name="realname" value="Full name"></input><br>
            Do you want your own personal folder for your file?<br>
            <input type="radio" name="pf" value="1">Yes</input>
            <input type="radio" name="pf" value="0" checked>No</input><br>
            <input type="text" class="form-control" name="pfn" value="Personal Folder Name"></input><br><br>
            Please tag your file:<br>
            <input type="radio" name="tag" value="other" checked>Other</input>
            <input type="radio" name="tag" value="funny">Funny</input><br>
            <input type="radio" name="tag" value="theoretic">Theoretic</input>
            <input type="radio" name="tag" value="sad">Sad</input><br>
            <input type="radio" name="tag" value="important">Important</input>
            <input type="radio" name="tag" value="informative">Informative</input><br>
            <input type="radio" name="tag" value="family">Family</input>
            <input type="radio" name="tag" value="friendly">Friendly</input><br>
            <input type="radio" name="tag" value="dangerous">Dangerous</input>
            <input type="radio" name="tag" value="horrible">Horrible</input><br>
            <input type="radio" name="tag" value="scary">Scary</input>
            <input type="radio" name="tag" value="musical">Musical</input><br>
            <input type="radio" name="tag" value="creative">Creative</input>
            <input type="radio" name="tag" value="ugly">Ugly</input><br>
      </div>
      <div class="modal-footer">
      <b>Uploader breaks if ", ', / or \ is used anywhere.</b>
        <button type="button" class="btn btn-default" data-dismiss="modal">Cancel request</button>
        <input type="submit" id="uploadsubmit" class="btn btn-primary" value="Upload" name="submit"></input>
        </form>

接下来是我的PHP处理程序(upload.php):

<center>
<?php

if(isset($_POST["disclaimer"]) && isset($_POST["realname"])) {

if($_POST["disclaimer"] != "1") {
    die("You didn't accept the disclaimer. Go back a page and read the disclaimer.");
}

if($_POST["realname"] == "Full name") {
    die("You didn't enter your real name. Go back and try again.");
} 

if($_POST["realname"] == "") {
    die("You didn't enter your real name. Go back and try again.");
}

} else {

    echo "Uh Oh! Something is going wrong! Attempting to repair.<br>";
    $_POST["realname"] == "real-name-post-error";

}


$personalfolder = $_POST["pf"];

//Base file names
$base_file_name = basename($_FILES["fileToUpload"]["name"]);
$base_file_name_path = $_FILES["fileToUpload"]["name"];

if (!empty($_SERVER['HTTP_CLIENT_IP'])) {
    $ip = $_SERVER['HTTP_CLIENT_IP'];
} elseif (!empty($_SERVER['HTTP_X_FORWARDED_FOR'])) {
    $ip = $_SERVER['HTTP_X_FORWARDED_FOR'];
} else {
    $ip = $_SERVER['REMOTE_ADDR'];
}

//Main script
echo "File(s) uploaded. Reading file list...<br>";
if($personalfolder == "1") {
$target_dir_ext = time()."_".basename($_FILES["fileToUpload"]["name"])."_".$ip.$_POST["realname"]."/".$_POST["pfn"]; // Prevent file already existing
} else {
$target_dir_ext = time()."_".basename($_FILES["fileToUpload"]["name"])."_".$ip.$_POST["realname"]; // Prevent file already existing
}
$structure = "uploads/".$_POST["tag"]."/".$target_dir_ext;
mkdir($structure, 0777, true);
$target_dir = "uploads/".$_POST["tag"]."/".$target_dir_ext."/";
$target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
echo "File(s) detected: <br>".$target_file."<br>";
echo "Checking file(s)...<br>";

$uploadOk = 1;
$imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
// Check if file already exists
if (file_exists($target_file)) {
    echo "Sorry, file already exists.<br>";
    $uploadOk = 0;
}
// Check file size
if ($_FILES["fileToUpload"]["size"] > 99999999) {
    echo "Sorry, your file is too large.<br>";
    $uploadOk = 0;
}
// Allow certain file formats
if($imageFileType != "jpg" 
&& $imageFileType != "png" 
&& $imageFileType != "jpeg"
&& $imageFileType != "GIF"
&& $imageFileType != "JPG"
&& $imageFileType != "JPEG"
&& $imageFileType != "PNG"
&& $imageFileType != "mp3"
&& $imageFileType != "MP3"
&& $imageFileType != "WAV"
&& $imageFileType != "wav"
&& $imageFileType != "mp4"
&& $imageFileType != "MP4"
&& $imageFileType != "swf"
&& $imageFileType != "SWF"
&& $imageFileType != "ogg"
&& $imageFileType != "OGG"
&& $imageFileType != "js"
&& $imageFileType != "JS"
&& $imageFileType != "txt"
&& $imageFileType != "TXT"
&& $imageFileType != "exe"
&& $imageFileType != "EXE"
&& $imageFileType != "zip"
&& $imageFileType != "ZIP"
&& $imageFileType != "rar"
&& $imageFileType != "RAR"
&& $imageFileType != "msi"
&& $imageFileType != "MSI"
&& $imageFileType != "ttf"
&& $imageFileType != "TTF"
&& $imageFileType != "svg"
&& $imageFileType != "SVG"
&& $imageFileType != "eot"
&& $imageFileType != "EOT"
&& $imageFileType != "woff"
&& $imageFileType != "WOFF"
&& $imageFileType != "woff2"
&& $imageFileType != "WOFF2"
&& $imageFileType != "gif" ) {
    echo "Sorry, only JPG, JPEG, PNG, GIF, OGG, MP3, MP4, WAV and SWF files are allowed.<br>";
    $uploadOk = 0;
}
// Check if $uploadOk is set to 0 by an error
if ($uploadOk == 0) {
    echo "Sorry, your file was not uploaded due to the reasons above.<br>";
// if everything is ok, try to upload file
} else {
    echo "File(s) OK. Attempting to move uploaded file(s) to the uploads directory...";
    if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
        echo "The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.<br>";
        $ul = "http://marksrtz.site50.net/uploader/".$target_file;
        echo "File URL: <a href='".$ul."'>".$ul."</a><br>";
        if($imageFileType == "jpg" 
        || $imageFileType == "png" 
        || $imageFileType == "PNG" 
        || $imageFileType == "gif" 
        || $imageFileType == "GIF" 
        || $imageFileType == "jpeg" 
        || $imageFileType == "JPEG" 
        || $imageFileType == "JPG") {
            echo 'Preview:<br><iframe width="1440px" height="900px" src="'.$ul.'"></iframe> ';
        } else {
            echo 'Preview:<br><iframe width="600px" height="400px" src="'.$ul.'"></iframe> ';
        }
    } else {
        echo "Sorry, there was an error uploading your file.";
    }
}
echo "<br>PHP Script was executed and ended correctly.";
?> 
</center>

问题是什么? PHP脚本的输出是:

  

上传的文件。读取文件列表...检测到的文件:   uploads / funny / 1422113393__188.29.64.63Mark琼斯/检查文件...   对不起,文件已经存在。对不起,只有JPG,JPEG,PNG,GIF,OGG,MP3,   允许使用MP4,WAV和SWF文件。抱歉,您的文件未上传   由于上述原因。

     

PHP脚本已执行并正确结束。

之前未检测到的是$_POST["disclaimer"]$_POST["realname"],但后来开始工作

现在它根本没有发送我想要上传的文件。

但是,如果我使用enctype它会发送文件但它不会发送POST变量。有没有办法可以在不创建其他表单的情况下同时发送POST变量和文件?

2 个答案:

答案 0 :(得分:0)

首先 - 不要把POST Vars当作它们! 总是检查一下

而不是

$ personalfolder = $ _POST [“pf”];

e.g。使用

$ personalfolder = trim(strip_tags(stripslashes($ _ POST [“pf”])));

答案 1 :(得分:0)

我只是继续做出这个答案。

000webhost最有可能默认上传2M。

您可以使用.htaccess覆盖它并将其值更改为

php_value memory_limit 30M
php_value post_max_size 100M
php_value upload_max_filesize 30M
例如

并放在服务器的根目录中。由于您无法修改其php.ini文件。

根据谷歌为您做的一些调查结果。

http://www.000webhost.com/forum/customer-assistance/202-file-upload-limit-2mb-set-php-ini.html

如上所述我们不允许在服务器上上传大文件(文件大小超过5 MB) 在我的组件(图片库)的后端,有一个声明上传文件限制为2Mb - 由php.ini设置 我用Joomla。有谁知道如何将它增加到5Mb? 它是在服务器上还是在我的文件系统中的某个地方?

此托管上传文件的限制为2Mb,您可以登录phpinfo()。

另外,只是出于争论的缘故:

表格在上传时需要有效的enctype;你没有。

将表单更改为:

<form action="upload.php" method="post" enctype="multipart/form-data">