2017-08-04 151 views
1

#'你好,我想上傳一個帶有html代碼和php代碼的文件(在兩個文件中分開)。我遵循我的意見的編碼規則,但是當我上傳一個文件時,它只是把我帶到我的index.php端,甚至沒有做任何我如果有條件的。 我現在嘗試了幾個小時的多種方式,並沒有奏效。任何人都可以看看,請(文件C的鏈接:\ XAMPP \ htdocs中\ MYSITE \上傳)?通過xampp上傳文件

HTML代碼#

<!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> 
+0

'action =「index.php」'表示表單將被髮布到「index.php」。如果您想將其發佈到其他頁面,請將其更改爲該文件。 –

+0

你會得到什麼錯誤。您可以通過添加error_report(E_ALL)來啓用錯誤報告。 ini_set(「display_errors」,1);'在你的php文件的頂部 –

+0

你是否禁用Php上傳。可以從php.ini配置文件中禁用Php上傳。看到這篇文章:https://stackoverflow.com/a/14785020/4508593。 file_uploads指令應該設置爲On –

回答

-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> 
+0

1.好的答案包含_explanation_,而不僅僅是代碼。 2.您可能希望刪除OP未要求的所有額外字段和邏輯。如果有的話,這個「答案」很可能會混淆OP,甚至更多的是這個代碼有自己的一些問題。 –

0

夥計們我發現了問題!首先感謝所有的答案,我真的很感謝這個論壇! 所以問題是我有很多PHP和HTML代碼寫在我的filevand上傳代碼CodeGo.net,我使用代碼來削減所有。即使如此,上面的代碼似乎禁止我的上傳代碼的一些輸出。有沒有任何方法可以將HTML + PHP代碼像#comment一樣剪切掉?