【问题标题】:Upload photo does not work in server上传照片在服务器中不起作用
【发布时间】:2015-11-03 22:04:47
【问题描述】:

代码在我的 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 = copy($_FILES['image']['tmp_name'], $newname); 中获得 $copied 的值。但它适用于我的本地主机

【问题讨论】:

  • 检查服务器中的文件夹权限
  • 这里可能会发生很多问题。上传文件夹的路径可能无效,上传可以通过 php.ini 禁用,文件可能太大,文件夹权限可能无效,等等......没有任何错误消息,我们无能为力。
  • 你能在描述中成为你的上传表单吗?
  • @SiddhuSiddharthaRoy:上传图片的其他模块都运行良好,除了这个。 AgeDeO:另外一个上传图片的功能很好,只有这个不行。
  • 我无法在if (!$copied || !$delete) 这一行中获得$copied的值

标签: php image-uploading


【解决方案1】:

可能你在host中没有forders权限,你需要在linux上给文件夹权限755,如果文件夹不存在则创建。

【讨论】:

  • 谢谢菲科!我对此很陌生。你的回答帮我解决了。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2012-10-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-10-01
  • 1970-01-01
  • 2014-09-18
相关资源
最近更新 更多