validation for image uploading in codeigniter - codeigniter

<form action="" method="POST" enctype="multipart/form-data">
<input type="file" name="multiple_article_logo[]" size="40" multiple/>
<input type="submit" name="submit" value="Upload">
</form>
if(isset($_FILES['multiple_article_logo']['name']) && !empty($_FILES['multiple_article_logo']['name']))
{
echo "Image is set";
}
else
{
echo "Image is unset";
}
If I am not uploading image just I will submit the form then the output should be 'Image is unset' but it is showing that image is set so I am not understanding how to do validation for multiple image uploading.
Please solve this issue .
If i will upload image then also it is showing image is set.
So can anyone suggest me how to do validation for image uploading?

Related

How to solve after upload the image missing in html

I am doing an image upload. The image successfully uploads but when press the button the image will missing.
This is my interface for image upload
when I select the image
the default image will change to the image I select
ut after I press the upload button to the backend it works but the selected image will become back the default one. Does anyone know how to solve it? Thanks in advance
Here is my code:
<form method="POST" action="url" enctype="multipart/form-data" id="upload">
#csrf
<div class="d-flex mb-2 ms-1 justify-content-md-center">
<img src="{{ asset('assets/images/placeholder.png') }}"/>
</div>
<label class="btn me-75 mb-0" for="picture">
<span class="d-none d-sm-block">Upload</span>
<input class="form-control" type="file" name="image" id="change" accept="image/*" hidden required/>
</label>
</form>

My form doesn't submit image file to controller store function, What is the problem

I want to send an image file to the controller store method, but the input file sends a temp file what is the problem, anyone can help me?
My Form:
<form method="POST" action="{{route('books.store')}}" enctype="multipart/form-data" >
#csrf
#method('POST')
<input type="file" name="cover_image" value="{{old('cover')}}">
<input type="submit" class="" value="send">
</form>
when I return:
return $request->cover_image;
the result is :
C:\xampp\tmp\phpF61B.tmp

Changing a text file from a HTML form

I'm just wondering if there's any way I can change the data held in my text file by filling out a HTML form on my website.
I've used AJAX to read to the website before but I don't know if its possible the other way round..
Ok so I don't really have any code yet cause I'm not sure how to do it.. but essentially, I want this HTML form:
<form name="updateGallery">
<b>Image:</b> <input type="image" name="image"/><br>
<b>Name:</b> <input type="text" name="name"/><br>
<b>Description and Price:</b> <input type="text" name="desPrice"/><br><br>
<input id="start" type="submit" onclick="submit" value="Update"/>
<input id="start" type="reset" value="Cancel"/>
</form>
to read to a text file I have set up containing information on items including - the name, an image of the item, description and price.

Honeypot protection with Ajax

Recently i got attacked by nasty auto-form fill bots which filled my shout form with all sorts of spam. My shout form consist from a html file with 2 textboxes,an ajax script(for refreshing without reloading) and my php file for handling all the inserting data into my DB.
I am thinking implementing a hidden textbox for a minimum protection against these bots but with no luck since i cant pass the honeypot data to my php file. My code:
HTML Form
<form class="form" method="post" action="postdata.php">
<fieldset id="inputs">
<input id="name" name="name" type="text" placeholder="name" maxlength="20">
<textarea id="message" name="message" type="text" placeholder="message" maxlength="255"></textarea>
</fieldset>
<fieldset id="actions">
<input type="submit" id="submit" value="Submit">
</fieldset>
</form>
Ajax script
$(function(){refresh_shoutbox();$("#submit").click(function(){var a=$("#name").val();var b=$("#message").val();var c="name="+a+"&message="+b;$.ajax({type:"POST",url:"postdata.php",data:c,success:function(d){$("#shout").html(d);$("#message").val("");$("#name").val("")}});return false})});
function refresh_shoutbox(){var a="refresh=1";$.ajax({type:"POST",headers:{"cache-control":"no-cache"},url:"postdata.php",data:a,success:function(b){$("#shout").html(b)}})};
postdata.php file
<?php
if($_POST['name'] or $_POST['message']) {
$name= $_POST['name'];
$message= $_POST['message'];
///do other stuff/////
?>
I will insert a hidden field in my html form
<input id="email" name="emails" style="display:none"></br>
but i cant manage to pass the extra value to my existing ajax script.Tried some code but with no luck.
Any help so i can get my shoutbox up and running again?

Image Submit Button Not Working Properly

I am trying to use an image to submit a form on my page. Here is the code I currently have, that works:
<form name="regForm" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="regForm" >
....input form here....
<input name="doRegister" type="submit" id="doRegister" value="Register">
</form>
What I am attempting to use, that does not work:
<form name="doRegister" action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" id="doRegister">
....input form here....
<input type="image" value="Register" src="../register.png" style="vertical-align: middle; height: 30px; width: 66px;" onsubmit="submit-form();" />
When clicking the button to submit, it reloads the page, without actually submitting the data.
Is this a Post v Get issue?
I also had this trouble in the past when doing something like this, try <input type="image" src="../register.png" alt="Register" name="doRegister" />
and in php use $_POST['x_doRegister'] (the x_ might not be needed)

Resources