Search code examples
phppostsizegetimagesize

PHP POST (i've seen all of post problems on dis site but they didn't helped)


hi guys i got problem with POST in php as u know,so ya, dats ma code

<form action="index.php?upload=true" method="post">
    <input type="file" name="photo" id="photo" value="upload image">
    <input type="submit" name="upload" value="DO IT"/>
</form>
<?php
if (isset($_GET['upload'])) {
    runMyFunction();
}
function runMyFunction(){
    $uploaded=$_POST['photo'];
    list($width, $height) = getimagesize($uploaded);
    echo "width: " . $width . "<br />";
    echo "height: " .  $height;
}
?>    

so my problem is: when i press upload button, i get errors: http://postimg.org/image/h39bvyt8j/ (i cant upload images i dont have reputation) and yes, all i need is: when i press upload button, image scale has to be written, as u see at the bottom of picture, for eg: i uploaded image, pressed uplaod and it wrote: Width:100px height: 150px thanks for any help!(i think there is something with Post method)


Solution

  • You have to add

      enctype="multipart/form-data"
    

    in the form and leave action blank. After that, add following code

      if (isset($_POST['upload'])) {
    
     runMyFunction();
     }
     function runMyFunction(){
     $uploaded=$_FILES['photo']['name'];
     move_uploaded_file($_FILES['photo']['tmp_name'], $uploaded);
     list($width, $height) = getimagesize($uploaded);
     echo "width: " . $width . "<br />";
     echo "height: " .  $height;
     }