Can someone please spot what I am doing wrong? I copied this over from a different page on my site where it works but I can't get it to work on this one. There are text inputs also that I have left out that are working as expected. Thanks.
<?php
if (isset($_POST["save"])) {
if (isset($_POST['pic'])){
//isset never detected when image is uploaded in html
}
}
<html>
<form class="form-horizontal" onsubmit="return checkSize(2097152)" enctype="multipart/form-data" data-toggle="validator" method="POST" action="profile.php">
<input id="pic" name="pic" type="file" accept="image/*" class="text-center center-block well well-sm">
<div class="form-group">
<label class="col-md-3 control-label"></label>
<div class="col-md-8">
<button class="btn btn-primary" name="save" id="save">Save Changes</button>
<a href="profile.php" class="btn btn-default" role="button">Cancel</a>
</div>
</div>
</form>
<script type="text/javascript">
//check image size func
function checkSize(max_img_size)
{
var input = document.getElementById("pic");
// check for browser support (may need to be modified)
if(input.files && input.files.length == 1)
{
if (input.files[0].size > max_img_size)
{
alert("Profile Picture must be less than " + (max_img_size/1024/1024) + "MB");
return false;
}
}
return true;
}
Addition: I just did a print_r($_POST); print_r($_FILES); and got without a picture being uploaded:
Array ( [nickname] => raySirSharp [motto] => Big gulps eh? [email] => razer88@hotmail.com [submit] => ) Array ( [pic] => Array ( [name] => [type] => [tmp_name] => [error] => 4 [size] => 0 ) )
With a picture uploaded:
Array ( [nickname] => raySirSharp [motto] => Big gulps eh? [email] => razer88@hotmail.com [submit] => ) Array ( [pic] => Array ( [name] => 12472627_211490652554223_5803523050459466916_n.jpg [type] => image/jpeg [tmp_name] => /tmp/phpvNCBzj [error] => 0 [size] => 70254 ) )
What can I use to detect if a picture has been uploaded or not?
I tried:
if (isset($_FILES['pic'])){ //always true :( }
Aucun commentaire:
Enregistrer un commentaire