Note that there are some explanatory texts on larger screens.

plurals
  1. POSingle-Click Avatar Upload Problems
    text
    copied!<p>I'm trying to make a single-click avatar upload form. This is the Javascript / php mixed code:</p> <pre><code>&lt;script type="text/javascript"&gt; function uploadavatar(){ $('#frmuploadavatar').submit(); } &lt;?php if(isset($_POST["btnuploadavatar"])){ $extension = pathinfo($_FILES["file"]["name"], PATHINFO_EXTENSION); $filename = pathinfo($_FILES["file"]["name"], PATHINFO_FILENAME); $allowedExts = array('jpg','png'); if(!in_array($extension, $allowedExts)){ ?&gt; $('#smlavatar').html("The uploaded file is not a jpg / png image!"); $('#smlavatar').attr("class","warning"); &lt;?php }else if($_FILES["file"]["size"]&gt;2097152){ ?&gt; $('#smlavatar').html("The uploaded file shouldn't exceed 2 megabytes!"); $('#smlavatar').attr("class","warning"); &lt;?php }else{ $uploadpath = "avatars/" . $filename . rand(1,1000000) . "." . $extension; move_uploaded_file($_FILES["file"]["tmp_name"], $uploadpath); ?&gt; $('#imgavatar').attr("src","&lt;?php echo $uploadpath; ?&gt;"); $('#smlavatar').html("New avatar upload successfully!"); &lt;?php } } ?&gt; &lt;/script&gt; </code></pre> <p>And here's the html code for form:</p> <pre><code>&lt;form action="register.php" method="POST" id="frmuploadavatar"&gt; &lt;input type="file" class="avatarupload" id="inpuploadavatar" name="avatar" onchange="uploadavatar()" /&gt; &lt;input type="button" id="btnuploadavatar" value="Upload New Avatar" style="width: 150px;" /&gt; &lt;/form&gt; </code></pre> <p>I didn't include the css code, but it's coded so that the file upload control is hidden and the button is visible but the user is actually clicking the file upload control instead of the button (file upload is on the front with z-index).<br/> I know that the function uploadavatar() is being called by testing it with an alert. However, the form "frmuploadavatar" doesn't get submitted as the JQuery code tells it to. Help?</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload