2012-06-23 79 views
0

向我的網站添加新項目時,我搜索要上傳到我的網站的項目圖片。找到該文件並完成表單後,我單擊添加。這應該把我的本地圖片,並將其存儲到我的圖像/租賃目錄。此外,圖片將自動按照項目編號命名,並將拇指添加到文件名(例如:109_thumb.jpg)。將圖像上傳到網站並重命名

以下是我在更改目錄後嘗試過的代碼,但無法使其再次運行。

<tr> 
<td align="right" class="tdTextBold">Thumb Image:   
</td> 
<td><font class="errMsgB">*</font></td> 
<td align="left"> 
<input id="fiuImage1" type="file" name="fileRentalThumbImage" /><div class="VCenter100" id="preview3" align="center"><? if ($rentalThumbImage!="" && $rentalThumbImage!=null)?><img src="../<? echo $rentalThumbImage; ?>" width="80" height="100" /></div> 
<!--<div class="column"> 
<table width="100%" cellpadding="0" cellspacing="0" border="0"> 

<tr> 

<td> 
<? 
if ($rentalThumbImage!="" && $rentalThumbImage!=null) 
{ 
?> 
<div class="VCenter100" id="preview1" align="center"><? if ($rentalThumbImage!="" && $rentalThumbImage!=null)?><img src="../<? echo $rentalThumbImage; ?>" /></div> 
<? 
} 
else 
{ 
?> 
<div class="VCenter100" id="preview1" align="center">Thumb Image</div> 
<? 
} 
?>   
</td> 
<td>&nbsp;</td> 
<td> 
<div class="column"> 
<div class="file_button"> 
<input id="uploadButton" style="WIDTH: 120px" type="button" value="Browse" name="file1" /> <input class="hiddenMask" id="fiuImage1" type="file" onchange="prePicture(this.name,'preview1')" name="fileRentalThumbImage" /> 
</div> 
<input style="WIDTH: 100px" onclick="document.frmMovie.rentalThumbImage.value='';removeImage('fiuImage1','preview1'); get('haveImage1').value='N';" type="button" value="Delete" name="remoteImage1"/> 
</div> 
<div style="CLEAR: both"> 
    </div>        </td> 
<td>&nbsp;</td> 
</tr> 
</table>  
</div> 
+0

請參閱http://php.net/manual/en/reserved.variables.files.php –

回答

0

您需要將圖像上傳到您的服務器,然後顯示它或使用HTML 5文件API。由於您使用的是PHP,因此前者的示例如下:

<form enctype="multipart/form-data" method="post" action=""> 
    <input id="fiuImage1" type="file" name="file" /> 
    <input type="submit" /> 
    <div class="VCenter100" id="preview3" align="center"> 
     <?php 
      if($_FILES["file"]) { 

       if (file_exists("upload/" . $_FILES["file"]["name"])) { 
        echo $_FILES["file"]["name"] . " already exists. "; 
       } else { 
        move_uploaded_file($_FILES["file"]["tmp_name"], 
        "upload/" . $_FILES["file"]["name"]); 
        //Stored in: upload/$_FILES["file"]["name"]; 
       } 
       ?> 
       <img src="upload/<?= $_FILES["file"]["name"] ?>" width="80" height="100" /> 
       <?php 
      } 

     ?> 
    </div> 
</form>