Dynadot โ€” .com Registration $8.99

Image uploader, uploads but still gives error

Spacemail by SpaceshipSpacemail by Spaceship
Watch

liam_d

The original NP Emo KidEstablished Member
Impact
25
Basically my image upload seems to work fine, it uploads the image in question ive tested that a few times, but it seems to then return with a blank error message.

Here is my code:
PHP:
function upload_item($item_id)
{
    global $site_config, $db_pxs, $lang, $pxs, $error;
    
    $error = '';
    
    // first we check if it is allowed
    $allowed_extensions = array('image/jpeg');
            
    if (in_array($_FILES['new_upload']['type'], $allowed_extensions))
    {
        // check file size not bigger than 1.47mb
        if ($_FILES['new_upload']['size'] > 1542000)
        {
            $error = 'Sorry file is too big!';
            return false;    
        }
    
        // THE MAIN FILE
        // give the file a random file name
        $filename = rand() . 'id' . $item_id . $_FILES['new_upload']['name'];
                
        // the actual file
        $source = $_FILES['new_upload']['tmp_name'];
                
        // where to upload to
        $target = "uploads/" . $filename;
        //
                
        if (move_uploaded_file($source, $target))
        {
            return $filename;
        }
            
        else
        {
            $error = 'Could not upload file, please contact the admin!';
            return false;    
        }
    }
    
    else
    {
        $error = 'Wrong file type, allowed to upload .jpg files only.';
        return false;    
    }
}
The image appears in my upload directory fine.
I don't see why it gives a blank error, i set only 3 error messages possible?
Here is the checking code:
PHP:
    // initial screenshot
    if ($_FILES['new_upload']['error'] == UPLOAD_ERR_OK)
    {
        if (upload_item($db_pxs->last_id()) == false)
        {
            $pxs->admin_error($error);
        }

        $screenshot_sql = "INSERT INTO `item_screenshots` SET `item_id` = {$db_pxs->last_id()}, `image` = '{$filename}'";
        $query_shot = $db_pxs->query($screenshot_sql);
    }
It doesn't seem to get to the screenshot sql, giving a blank error message above , yet it does upload the file :S

Any help would be great!
 
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
.US domains.US domains
Instead of $error = ''; try $error; or $error = false;


Bruce
 
0
•••
Nevermind it is fixed now, i did return true and set $filename to global to use outside and works now :)
 
0
•••
it was an easy fix its just that you didnt see it clearly!
 
0
•••
Appraise.net
Unstoppable Domains
Domain Recover
DomainEasy โ€” Zero Commission
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back