2013-05-08 95 views
2

我正嘗試使用簡單的HTML表單和PHP將圖像(用戶的個人資料圖片)上傳到我的服務器。服務器響應中的鏈接不可點擊

HTML

<?php include("../../header_init.php"); ?> 
<div class="PageContainer"> 
    <div class="PageTitle">Profile Initialization - Step 3 of 4</div> 
    <div id="InitStepDisplay_Stretched"> 
     <p><span class="BigText">Display Image</span></p> 
     <br /> 
     <div id="PictureDisplayInit"></div> 
     <div id="Image_Upload_Instructions"> 
      <form id="imageform" method="post" enctype="multipart/form-data" action="../../UploadImage.php" target="ResponseArea" > 
       <table> 
        <tr> 
         <td><span class="SmallText">The photo must be less than 2MB in size and of formats JPEG, PNG, GIF or BMP.</span></td> 
        </tr> 
        <tr> 
         <td><input class="FileInput" type="file" name='file' id="file" accept="image/*" /></td>       
        </tr> 
        <tr> 
         <td><input class="Button" type="submit" name="submit" value="Upload"></td> 
        </tr>      
       </table>      
      </form> 
      <iframe name="ResponseArea"></iframe> 
     </div>        
    </div><!-- End of InitStepDisplay_Stretched -->    
</div><!-- End of div PageContainer --> 

PHP

if ($_FILES['file']['size'] > 0) 
{ 
    $filename = basename($_FILES['file']['name']); 
    $size = $_FILES['file']['size']; 
    $valid_formats = array("jpg", "png", "gif", "bmp", "jpeg","GIF","JPG","BMP","PNG"); 
    list($txt,$ext) = explode(".",$filename); 
    if (in_array($ext, $valid_formats)) 
    { 
     if ($size < 2098888) 
     { 
      // TO DO: Remove any older profile picture      
      $clean_name = str_replace(" ", "_", $txt)."_".time().".".$ext; 
      $query = "UPDATE tblSomething SET MyPicture = '" . $clean_name . "' WHERE CurrentUserID = " . $_SESSION['CurrUserID']; 
      $update_tblSomething = $conn->query($query); 
      if ($update_tblSomething == true) 
      { 
       $newname = 'images/profile/'.$clean_name; 

       if ($_FILES['file']['error'] == 0 && move_uploaded_file($_FILES['file']['tmp_name'], $newname)) 
       { 
        $uploaded = $newname;       
        echo("<img src='../../".$uploaded."' class='PictureDisplayInit Stretch'> <input type='hidden' name='actual_image_name' id='actual_image_name' value='$uploaded' />"); 
        $query = "UPDATE tblAnotherOne 
              SET Step3Complete = 1, LastUpdated = '" . date("Y-m-d H:i:s") . "' WHERE CurrentUserID = " . $_SESSION['CurrUserID']; 
        $update_TPC = $conn->query($query); 
        if ($update_TPC) 
        { 
         echo "<br /><br /><br /><br /><br /><span class='SuccessText'>File uploaded successfully. You're almost done.</span><br /><br /><a href='../step4/'>Proceed to final step</a>"; 
        } 
        else 
        { 
         echo "<script>location.href='../../error.php?code=3'</script>";         
        }        
       } 
       else 
       { 
        echo "<span class='ErrorTextSmall'>Image could not be uploaded. Please try again.</span>"; 
       } 
      } 
      else 
      { 
       "<script>location.href='../../error.php?code=3'</script>"; 
      }      
     } 
     else 
     { 
      echo "<span class='ErrorTextSmall'>File size exceeded 2MB! Please choose a smaller file.</span>"; 
     } 
    } 
    else 
    { 
     echo "<span class='ErrorTextSmall'>Invalid image file format. Only jpg, png, gif and bmp formats allowed.</span>"; 
    } 
} 
else 
{ 
    $utility->MessageBox("Please select a file to upload."); 
} 

的問題

這部分在PHP代碼輸出具有的鏈路的 「成功語句」( 「繼續執行最終步驟」) 。此鏈接不可點擊。

if ($update_TPC) 
{ 
    echo "<br /><br /><br /><br /><br /><span class='SuccessText'>File uploaded successfully. You're almost done.</span><br /><br /><a href='../step4/'>Proceed to final step</a>"; 
} 

我至今嘗試過(無工作)

  1. 二手I幀作爲可以在代碼中可以看出。
  2. 在我的css文件中,增加了Z-index:10;單獨的類.SuccessText都和內含div(#Image_Upload_Instructions)

這裏是最離奇的一部分(線索你聰明的人)

當我查看網頁源文件已被處理後顯示成功消息,我無法在iframe中看到成功消息。

請幫忙!我已經在這裏住了2晚,沒有運氣。

這裏是供您參考CSS:

#InitStepDisplay_Stretched { 
    position: relative; 
    width: 700px; 
    min-height: 400px; 
    overflow: auto; 
    margin-left: auto; 
    margin-right: auto; 
    margin-top: 70px; 
    margin-bottom: 10px; 
    padding: 50px; 
    -moz-border-radius: 5px; 
    -webkit-border-radius: 5px; 
    border-radius: 5px; 
    border: 1px solid #CFCFCF; 
    background-color: #FFFFEF; 
} 
#InitStepDisplay_Stretched td { 
    padding-right: 10px; 
    padding-bottom: 10px; 
    vertical-align: top; 
    line-height: 1.5; 
} 
#Image_Upload_Instructions { 
    position: fixed; 
    top: 280px; 
    left: 290px; 
    height: 700px; 
    width: 440px; 
    z-index: 10; 
} 
#InitStepDisplay_Stretched a { 
    background-color: #3F8FCA; 
    color: #FFFFFF; 
    padding: 5px; 
    text-decoration: none; 
    -moz-border-radius: 5px; 
    -webkit-border-radius: 5px; 
    border-radius: 5px; 
} 
#InitStepDisplay_Stretched a:visited { 
    background-color: #3F8FCA; 
    color: #FFFFFF; 
} 
#InitStepDisplay_Stretched a:hover { 
    background-color: #3F74BF; 
    color: #DEEFEA; 
} 
#InitStepDisplay_Stretched a:active { 
    background-color: #3F8FCA; 
    color: #FFFFFF; 
} 
#InitStepDisplay_Stretched ul { 
    list-style: circle; 
    margin-left: 15px; 
} 
.PictureDisplayInit { 
    position: relative; 
    top: 20px; 
    left: 470px; 
    width: 200px; 
    height: 200px; 
    -webkit-border-radius: 5px; 
    -moz-border-radius: 5px; 
    border-radius: 5px; 
    border: 2px dashed #CFCFCF; 
    background-repeat: no-repeat; 
} 
.Stretch { max-width:200px; max-height:200px; width:auto; height:auto; } 

.FileInput { 
    padding: 10px 5px; 
    width: 440px; 
    border: 1px solid #CFCFCF; 
} 
+2

嘗試你的結果 – 2013-05-08 05:03:21

+0

+1頁上運行HTML驗證完整和整潔後 – 2013-05-08 05:47:33

+0

感謝您的評論BART小號 – KalC 2013-05-08 13:20:23

回答

0

我將echo語句的內容封裝在一個div中,鏈接可點擊。

if ($update_TPC) 
{ 
    echo "<div><br /><br /><br /><br /><br /><span class='SuccessText'>File uploaded successfully. You're almost done.</span><br /><br /><a href='../step4/'>Proceed to final step</a></div>"; 
} 
+0

如果有人可以向我解釋爲什麼這可能起作用,我會非常感激。 – KalC 2013-05-09 04:08:29

-1

你不能在../一個href。它不會將其視爲鏈接。它必須是/location.php或完整的http://blah.com鏈接。該鏈接不是一個有效的鏈接。

+1

不是這樣,'../ foo.bar'是一個有效的相對URL,它引用了一個名爲'foo.bar'的資源,位於當前目錄之上的一個目錄中。 – CBroe 2013-05-08 08:30:22

+0

嗨mcrtr,我第二什麼CBroe說。我使用了像www.googl.com這樣的鏈接,它仍然是不可點擊的。我認爲這是一個Z指數問題。 – KalC 2013-05-08 13:17:17