2012-06-23 40 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>