php code in wordpress for image uploading

12,348

Solution 1

Like @Musa says, remove the check:

<?php
$uploaddir = './uploads/image/large_image/'; 
$file = $uploaddir . basename($_FILES['image2']['name']); 
$raw_file_name = $_FILES['image2']['tmp_name'];
if (move_uploaded_file($_FILES['image2']['tmp_name'], $file)) { 
    echo "success"; 
} else {
    echo "error";
}

Solution 2

list($width, $height) = getimagesize($_FILES['image2']['tmp_name']);
if ($width==360 && $height==514) {
    if (move_uploaded_file($_FILES['image2']['tmp_name'], $file)) { 
        echo "success"; 
    } 
else {
    echo "error";
}

It is right in your code if you read it... Here it says that it has to be equal to 360x514, just get rid of that IF statement, and just skip to the move_uploaded_file command.

Share:
12,348

Related videos on Youtube

user1819199
Author by

user1819199

Updated on June 04, 2022

Comments

  • user1819199
    user1819199 almost 2 years

    Please help with php code:

    I have following code what makes only 360x514 images to be uploaded only. My question is: how can I edit it to make any size uploadable without error message?

    <?php
    $MAXIMUM_FILESIZE = 5 * 1024 * 1024; 
    $uploaddir = './uploads/image/large_image/'; 
    $file = $uploaddir . basename($_FILES['image2']['name']); 
    $raw_file_name= $_FILES['image2']['tmp_name'];
    list($width, $height) = getimagesize($_FILES['image2']['tmp_name']);
    if ($width==360 && $height==514) {
    if (move_uploaded_file($_FILES['image2']['tmp_name'], $file)) { 
    echo "success"; 
    } 
    else {
    echo "error";
    }
    }else {
    echo "size_error";
    }
    ?>