代码在我的localhost(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
中获得$copied = copy($_FILES['image']['tmp_name'], $newname);
的值。但它适用于我的localhost
答案 0 :(得分:0)
也许你没有托管主机的forder,你需要在linux上给予文件夹权限755并创建if文件夹不存在。