Ryan Claxton Ryan Claxton - 1 year ago 88
HTML Question

Form image submit not detected

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.

if (isset($_POST["save"])) {

if (isset($_POST['pic'])){
//isset never detected when image is uploaded in 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>


Answer Source

To accept a file from a HTML form you need to use the $_FILES instead of the $_POST. For example you can use $_FILES["pic"]["name"] to get the file name.

From there you can move the picture to a new location like this:
move_uploaded_file($_FILES["pic"]["tmp_name"], "/var/tmp/pic.jpg")

More info is available at http://www.w3schools.com/php/php_file_upload.asp

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download