1
代碼在我的本地主機(xampp)中運行良好,這是我的網頁的編輯部分。但是當我把我的服務器,上傳照片功能不起作用(不上傳圖像到服務器)。任何幫助將非常感激。以下是我上傳照片的代碼。上傳照片在服務器中不起作用
define ("MAX_SIZE","1000");
$errors=0;
$image=$_FILES['image']['name'];
if ($image == "")
{
$uploadmsg = '<br /><font color=red>'.ERR_BLANK_IMAGE_FIELD.'</font>';
$errors=1;
}
if ($image)
{
$filename = stripslashes($_FILES['image']['name']);
$extension = base_getExtension($filename);
$extension = strtolower($extension);
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
$uploadmsg = '<br /><font color=red>'.ERR_UNKNOW_IMAGE_EXTENTION.'</font>';
$errors=1;
}
else
{
$size=filesize($_FILES['image']['tmp_name']);
if ($size > MAX_SIZE*1024)
{
$uploadmsg = '<br /><font color=red>'.ERR_EXCEEDED_SIZE.'</font>';
$errors=1;
}
$newname="images/eitem_".$itemPart.".".$extension;
if($photo != "images/eitem_item_default.png")
{
$delete = unlink($photo);
}
else
{
$delete=1;
}
$copied = copy($_FILES['image']['tmp_name'], $newname);
if (!$copied || !$delete)
{
$uploadmsg = '<br /><font color=red>'.ERR_IMAGE_UPLOAD_UNSUCCESS.'</font>';
$errors=1;
}
}
if(isset($_POST['save']) && !$errors)
{
$uploadmsg = "<br /><font color=red>".MSG_IMAGE_UPLOAD_SUCCESS."</font>";
eitem_editItemPhoto($cid,$newname);
eitem_editItem($cid,$itemPart,$shortDesc,$longDesc,$categoryList,$brandList,$packDetails,$minOrder,$supplier,$price);
}
}
else
{
eitem_editItem($cid,$itemPart,$shortDesc,$longDesc,$categoryList,$brandList,$packDetails,$minOrder,$supplier,$price);
}
HTML
<div class="cell bottomBorder" style="width:170px; height:170px;vertical-align:middle; text-align:center;padding:5px;">
<img src="../eitem/<?php echo $photo; ?>" id="imge_path" style="height:150px; width:120px"/>
</div>
<div class="cell bottomBorder" style="vertical-align:middle;">
<input type="file" name="image" id="image">
<div>(150px x 120px)</div>
<?php echo $uploadmsg; ?><br />
<span class="note">Please use an image with .png,.jpg or .gif file format.</span>
</div>
</div>
編輯
當我試圖呼應出服務器的價值我不能在這行$copied = copy($_FILES['image']['tmp_name'], $newname);
得到$copied
值。但它在我的本地主機上工作
檢查服務器中的文件夾權限 –
可能是很多問題發生在這裏。上傳文件夾的路徑可能無效,可以通過php.ini禁用上傳文件,文件可能會變大,文件夾權限可能無效等等。沒有任何錯誤消息,我們無法做到。 – AgeDeO
你能說明你的上傳表單嗎? – ThinkTank