[英]uploading image to website and rename
將新商品添加到我的網站時,我搜索該商品的圖片以上傳到我的網站。 找到文件並填寫表格后,單擊添加。 這應該是拍攝我的本地照片並將其存儲到我的images / rental目錄中。 此外,圖片將自動以商品編號命名,並將拇指添加到文件名中(例如: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> </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> </td>
</tr>
</table>
</div>
您需要將圖像上傳到服務器,然后顯示它或使用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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.