javascript - Undefined fileField/ how to hide image if the fileField is = "" -
a newbie here. apologize in advance grammar, not first language.
okay, have form, , includes file field (which optional in validation) show picture user selected (before pressing submit). , yes, works.
however, problem is, if go , press file field again, press 'cancel', unselect selected file shown image won't go away. way user won't confused if change mind selecting image. used javascript showing image after user selects.
so here's code (i'll try exclude irrelevant parts):
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script> <script> function showimage(input) { if (input.files && input.files[0]) { var reader = new filereader(); reader.onload = function (e) { $('#newimage') .attr('src', e.target.result) .width(90) .height(90); }; reader.readasdataurl(input.files[0]); } } </script> <form action="edit_product.php" enctype="multipart/form-data" name="myform" id="myform" method="post" class="form-inline" role="form"> <input type="file" name="filefield" id="filefield" onchange="showimage(this);" /> <img id="newimage" src="#" alt="new image" />
so tried replacing last line with:
<?php if ($_files['filefield']['tmp_name'] != "") { echo '<img id="newimage" src="#" alt="new image" />'; } ?>
and if variations same conditions like:
if(!empty($_files["filefield"]["tmp_name"]))
but error keeps telling me
php error message notice: undefined index: filefield
it's php doesn't know told him field named 'filefield', wonder what's wrong , why keep getting error? please help, i've searched through no avail did find answers. :) i'm sorry, code may messy you.
Comments
Post a Comment