通过xampp上传文件

时间:2017-08-04 13:26:12

标签: php html

#'你好,我想上传一个带有html代码和php代码的文件(分成两个文件)。在我看来,我遵循编码规则,但是当我上传文件时,它只是将我带到我的index.php一边,甚至没有做任何我的if条件。 我现在尝试了几个小时的多种方式而且它没有用。有人可以看一下吗?(文件C:\ xampp \ htdocs \ mySite \ uploads的链接)

HTML CODE#

<!DOCTYPE HTML>
<html>
<body>

<form action="index.php" method="post" enctype="multipart/form-data">
Datei: <input type="file" name="hochladen" id="hochladen"/>
<input type="submit" value="Upload!!!" name="submit"/>
</form>


</body>
</html>

PHP代码

<!DOCTYPE HTML>
<html>
<body>


<?php 
$ziel = "uploads/";
$zieldatei = $ziel . basename($_FILES["hochladen"]["name"]);
if(move_uploaded_file ($_FILES["hochladen"]["tmp_name"], $zieldatei )){
echo "File uploaded";}

else { echo "error";}
print_r ($_FILES);
var_dump ($_FILES);
echo $_FILES;
?>

</body>
</html>

2 个答案:

答案 0 :(得分:0)

Guys I found the problem! Firstly thanks for all the answers I really appreciate that forum! So the Problem was I had much PHP and HTML Code writen down over the upload Code in my filevand I used the Code to cut all of it out. Even then the upper Code seems to prohibit some outputs of my upload code. Is there any save way to cut HTML + PHP Code out like a #comment ?

答案 1 :(得分:-2)

这应该可以帮到你

PHP代码

if(isset($_POST['editlogopic']))
{
    $logopic = ($_FILES['logopic']['name']);
    $logopicExt = end(explode('.', $logopic));
    $logopicExt = strtolower($logopicExt);

    if($logopic!="")
    {
        if($logopicExt != "png" && $logopicExt != "svg")
        {
            $file_upload="false";
            $errorMsg=$errorMsg."<div class='card-panel white-text red lighten-2 center-align'>Image file should be .png or .svg type</div>";
        }
    }

    if($errorMsg=='')
    {
        $targetlogopic = 'temp_name'.".".$logopicExt;

            $target_image_gallery_info = "../images/";
            move_uploaded_file($_FILES['logopic']['tmp_name'],  $target_image_gallery_info.basename($targetlogopic));
            header('Location: info?ref=success');
    }
    else
    {
        $msg = '<div class="card-panel white-text red lighten-2 center-align">Background Image not Change!</div>';
    }
}

HTML代码

    <form method="post" class="col s12" action="service.php" enctype="multipart/form-data">
                        <div class="row">
                            <div class="col s12">
                                Logo Image
                            </div>
                        </div>
                        <div class="row valign-wrapper">
                            <div class="input-field col s12 m1 l1 center-align">
                                <img src="../images/<?php echo $row1['logopic']?>?<?php echo $dummy; ?>" class="circle materialboxed" width="50px" height="50px">
                            </div>
                            <div class="file-field input-field col s12 m9 l9">
                                <div class="btn">
                                    <span>Image</span>
                                    <input type="file" id="logopic" name="logopic">
                                </div>
                                <div class="file-path-wrapper">
                                    <input class="file-path" type="text" placeholder="Select .png or .svg photo only!">
                                </div>
                            </div>
                            <div class="input-field col s12 m2 l2">
                                <button class="btn waves-effect waves-light" type="submit" name="editlogopic">Update
                                    <i class="material-icons right">send</i>
                                </button>
                            </div>
                        </div>
                    </form>