【问题标题】:image from database but input required still fires来自数据库但需要输入的图像仍然会触发
【发布时间】:2018-09-04 22:06:02
【问题描述】:

如果我从数据库接收到变量形式的数据,我如何告诉我的 INPUT FIELD 存在图像。 因为我的输入必须是必需的..

我从数据库中检索之前在页面上选择的图像,但输入不知道文件存在,因为该文件是一个 php 变量..

我的帮助下面的代码。

感谢您的任何建议。非常感谢。

<div class='imagecontainer'>    
    <div class='image1' id='image1'  title='Upload The 1st Image'  >

 <img id='img1' <?php if (!empty($i1url)) { echo " src='{$i1url}' "; } else { echo " src='' style='opacity:0;' "; } ?> onclick=' document.getElementById("sellimage1").click();'  class='imageclass'  ></img>

    <div class='cancel'  onClick='cancelimage(sellimage1 , img1, old1);' title='Delete This Image'> </div>  

    <input type='file' class='fileinput'  id='sellimage1' name='sellimage1' onchange='addimg(this , img1, image1);' value='' accept='image/*' required ></input>
    <input id='Chosen1' type='hidden' name='Chosenimg1' value='<?php echo $i1url; ?>' ></input> 

</div>

【问题讨论】:

  • 这行得通吗 --- 不行!!!

标签: php html image jscript


【解决方案1】:

JS

input.required=false; input.required=true;

我的解决方案是与 PHP 一起在 INPUT 字段上进行的

<div class='image1' id='image1'  title='Upload The 1st Image'  >

     <img id='img1' <?php if (!empty($i1url)) { echo " src='{$i1url}' "; } else { echo " src='' style='opacity:0;' "; } ?> onclick=' document.getElementById("sellimage1").click();'  class='imageclass'  ></img>

    <div class='cancel'  onClick='cancelimage(sellimage1 , img1, old1);' title='Delete This Image'> </div>  

    <div class='magnify' title='Magnify This Image' <?php echo " src='{$i1url}' "; ?> > </div>      

    <input type='file' class='fileinput'  id='sellimage1' name='sellimage1' onchange='addimg(this , img1, image1);' <?php if (!empty($i1url)) { echo " value='{$i1url}' "; } else { echo " value='' "; } ?> accept='image/*' <?php if (empty($i1url)) { echo " required "; } ?>   ></input>

    <input id='old1' type='hidden' name='oldimg1' value='<?php echo $i1url; ?>' ></input>   

</div>

JS

function cancelimage(a , b , c){


var image = b;

var value1 = a;

var value2 = c;

value1.value=null;
value2.value=null;

b.style.opacity='0';
b.style.transition='2s';

value1.required=true;


return

}





function addimg(input , image , main) {
 var lb=image;      
 var ab=main;       

 input.required=false;

 lb.src="../pageimages/loader.gif";
 lb.style.transition='.4s';
 lb.style.opacity='1';          


    if (input.files && input.files[0]) {


        var reader = new FileReader();
        reader.onload = function (e) {
        sr=(e.target.result)
                    };

        reader.readAsDataURL(input.files[0]);
    }

        setTimeout(function(){
        lb.src=""+sr;
        },2000);


}

【讨论】:

  • 但我认为这是一个非常脆弱的解决方法,我相信有一种更好的方法更安全和更受欢迎。任何进一步的信息仍将不胜感激。谢谢。
猜你喜欢
  • 2012-04-22
  • 1970-01-01
  • 2011-02-06
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2012-04-06
  • 2019-12-14
相关资源
最近更新 更多