代码在本地主机(examplep)中运行良好,这是我的网页的编辑部分。但当我把照片放在服务器上时,上传照片的功能不起作用(不将图像上传到服务器)。任何帮助都将不胜感激。下面是我上传照片的代码。
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
的值。但它在我的本地主机中工作
很可能您在主机中没有forders的权限,您需要在linux上授予文件夹755权限,并在文件夹不存在的情况下创建。