So, I have a form to post a text to a blog. One of the informations include an image.
<label class="w3-text-black">Image:</label>
<input name="image" type="file"/>
<br></br>
<button name="submit" type="submit" class="w3-btn w3-gray w3-hover-black">Send</button>
And I have the PHP part that receives all that information, but only sends the rest to the DB and uploads the image to my server if the image is a PNG.
$temp = explode(".", $_FILES['image']['name']);
if (strstr('.png', end($temp))){ //condition }
This code worked when used in my localhost, but once i uploaded it to my server, this error appeared: Warning: strstr(): Empty needle
And what $temp does is separate the extension with the use of explosion.
After that, i change the name of my file, so i can access it later with js.
$sqlImg = "SELECT * FROM posts WHERE post_id = (SELECT MAX(post_id) FROM posts)";
$resid = mysqli_query($conn, $sqlImg);
$linha = mysqli_fetch_assoc($resid);
$id = $linha['post_id'];
$path = 'blogimg/blog_img' . $id . '.' . end($temp);
if (move_uploaded_file($_FILES['imagem']['tmp_name'], $path)){}