Staying Browser File after submitting - PHP -
<? $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 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>
this program working correctly. when enter verdict of sport
, click save
, shows select photo
, have entered/typed showing in verdict of sport
.
without entering verdict of sport
, select photo-->click 'save', shows 'enter ur opinon'. and have selected photo disappear.
so need solution browsed file should not disappear when 'save'.
there simpler way deal image uploads. try wideimage.sourceforge.net/
that being said, trying do? want upload image , show right?. have have block src set path of file.
Comments
Post a Comment