【问题标题】:Staying Browser File after submitting - PHP提交后保留浏览器文件 - PHP
【发布时间】:2013-05-21 04:46:16
【问题描述】:
<?
$img="";
$comment="";
if(isset($_POST['save']))   
{
    $e="0";
    $comment=trim($_POST['comment']);
    if($comment=="")
    {
       $sel5="<--Enter Ur Opinon";
       $e="5";
       $code5="";
    }
    if($_FILES['photo']['name']=="")
    {
       $sel6="<--Select Your Photo";
       $e="6";
       $code6="";
    }
    else
    {
       $rand=rand().time();
       $photo_name=$_FILES['photo']['name'];
       $photo_tmp_name=$_FILES['photo']['tmp_name'];
       $photo_name1=explode(".",$photo_name);
       list($width,$height) = getimagesize($photo_tmp_name);
       if($photo_name1[1]=="jpeg"||$photo_name1[1]=="jpg"||$photo_name1[1]=="gif")
       {
         if($width<=365)
         {
            $img="1";
            $photo_name1=$photo_name[0].$rand.".".$photo_name[1];
            move_uploaded_file($photo_tmp_name,"Images/{$photo_name1}");
         }
         else
         {  
            $sz1="";
            $e="7";
            $sz_err="Not Perfect Size";
            $code6="";  
         }
     }
     else
     {
        $sz2="";
        $e="8";
        $sz_err="Not correct Type";
        $code6="";
     }  
     }
     if($e==0)
     {
        $suc="Success";
        $comment="";
     }
     }
?>

<html>
<body>
<style type="text/css" >
.message{color: red; font-weight:bold; }
.error{border:1px solid red; }
        </style>
            <table>
            <tr>
            <td>Verdict Of Sport</td>
            <td>
            <textarea name="comment" cols="40" rows="6" <? if(isset($code5))
            {echo "class=error" ;} ?>> <? echo $comment; ?>
            </textarea>
            </td>
            <td><? if(isset($sel5)){ echo "<p class='message'>".$sel5."</p>"; }?>
            </td>
            </tr>
            <tr>
            <td>Your Picture</td>
            <td <?php if(isset($code6)) {echo "class=error" ;} ?>>
            <input type="file" name="photo" value="<? if($img==="1") { echo $photo_name; } ?>"/>
            </td>
            <td>
            <? if(isset($sel6)){ echo "<p class='message'>".$sel6."</p>"; }?>
            <? if(isset($sz1)){ echo "<p class='message'>".$sz_err."</p>";}?>
            <? if(isset($sz2)){ echo "<p class='message'>".$sz_err."</p>";}?>
            </td>
    </tr>
    <tr>
    <td colspan="3" align="center">
    <input type="submit" name="save" /><?=$suc;?>
    </td>
    </tr>
            </table>
            </body>
            </html>

此程序运行正常。当我输入Verdict of Sport,然后单击save 时,它会显示Select Your Photo,而我输入/键入的内容会显示在Verdict of Sport 中。
但是不输入Verdict of Sport,然后我选择Photo-->点击'save', 它显示“输入您的意见”。 我选择的照片消失了。

所以我需要解决方案,当我“保存”时浏览文件不应该消失。

【问题讨论】:

    标签: php file photo


    【解决方案1】:

    有一种更简单的方法来处理图片上传。试试wideimage.sourceforge.net/‎

    话虽如此,你到底想做什么?您想上传图像并显示它吗?为此,您必须将 src 设置为文件路径的块。

    【讨论】:

      【解决方案2】:

      您可以为“保存”功能使用 AJAX 提交。这将允许您发送请求并获得响应,而无需刷新页面。 JQuery 是一个很棒的 JavaScript 库,具有很好的 AJAX 集成。

      【讨论】:

        猜你喜欢
        • 2012-11-22
        • 2014-01-03
        • 2011-07-27
        • 2016-07-04
        • 1970-01-01
        • 1970-01-01
        • 2016-11-11
        • 2019-03-13
        • 1970-01-01
        相关资源
        最近更新 更多