Can someone help me out as i'm quite new to coding.
I'm using smarty template engine and i have this form that is for users to update they're cover image or add one but my problem is that every time i or a user reloads the page the form posts a new image everytime without even pressing submit button.
Here is the form.
<form method="post" enctype="multipart/form-data" id="cover_upload">
<input type="file" name="cover_file" id="file" class="cover_input" />
<input type="hidden" name="action" value="change_cover" />
<a class="submit_form_button" style="float:right" onclick="jQuery('#cover_upload').submit();" href="javascript:void(0);">Change</a>
</form>
And here is the php
if (isset($action) && $action=='change_cover' && isset($_SESSION['loggeduser_id'])){
if (isset($_FILES['cover_file']['name']) && $_FILES['cover_file']['name']){
if (($_FILES["cover_file"]["type"] == "image/gif") || ($_FILES["cover_file"]["type"] == "image/jpeg") || ($_FILES["cover_file"]["type"] == "image/pjpeg") || ($_FILES["cover_file"]["type"] == "image/png")){
$filename = $_SESSION['loggeduser_id']."_".date("YmdHis").".jpg";
if (move_uploaded_file($_FILES["cover_file"]["tmp_name"],"$basepath/thumbs/users/covers/" . $filename)){
$user = new User();
$user->update($_SESSION['loggeduser_id'],array("cover" => $filename));
$_SESSION['loggeduser_details']['cover'] = $filename;
}
}
}
}
Could someone please show or tell me what is going on and how to fix this thanks