非常抱歉,如果這已被回答,但我一直在尋找谷歌一段時間,並沒有找到答案。如何更改已上傳的照片。 PHP
我的問題
我上傳了一個PHP文件用於我的網站。我想成爲麥芽酒,讓用戶選擇更改他們上傳的圖像。我設法做到了,當他們只能上傳1張圖片,但現在我試圖添加更多。他們可以添加多張照片,但當涉及到改變他們即時通訊有問題時。
這裏是我的1幅圖像(工作)代碼
$newname = "$pid.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$newname");
header("location: inventory_list.php");
exit();
這是我用來改變它的代碼。
if ($_FILES['fileField']['tmp_name'] != "") {
// Place image in the folder
$newname = "$pid.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$newname");
}
header("location: inventory_list.php");
這就是我現在已將代碼更改爲多個圖像。
$image1 = "$pid Image1.jpg";
$image2 = "$pid Image2.jpg";
$image3 = "$pid Image3.jpg";
$image4 = "$pid Image4.jpg";
$image5 = "$pid Image5.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$image1");
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$image2");
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$image3");
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$image4");
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$image5");
header("location: inventory_list.php");
這是我已經試過,但我知道有一個在如果
if ($_FILES['fileField']['tmp_name'] != "") {
// Place image in the folder
$image1 = "$pid Image1.jpg";
$image2 = "$pid Image2.jpg";
$image3 = "$pid Image3.jpg";
$image4 = "$pid Image4.jpg";
$image5 = "$pid Image5.jpg";
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$image1");
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$image2");
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$image3");
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$image4");
move_uploaded_file($_FILES['fileField']['tmp_name'], "../inventory_images/$image5");
}
一個邏輯上的錯誤,這是我表單的一部分
<tr>
<td align="right">Product Image: 1</td>
<td><div class="single">
<a href="../inventory_images/<?php echo $id; ?> Image1.jpg" rel="lightbox" title="<?php echo $product_name; ?>"><img src="../inventory_images/<?php echo $id; ?> Image1.jpg" width="142" height="188" alt="<?php echo $product_name; ?>" /></a>
</div></td>
</tr>
<tr>
<td align="right"></td>
<td><label>
<input type="file" name="Image1" id="Image1" />
</label></td>
</tr>
感謝您的幫助
什麼是$ PID? – Hkachhia 2012-07-05 11:35:34
抱歉$ pid是產品ID。將產品與圖像聯繫起來。 – Will 2012-07-05 12:17:59