Click here to Skip to main content
14,606,383 members
Rate this:
Please Sign up or sign in to vote.
See more:
The error message:
syntax error, unexpected '$image_name' (T_VARIABLE)


The code:

if (isset($_POST['add-post'])) {
    adminOnly();
    $errors = validatePost($_POST);

    ($_FILES['image']['name'])
        $image_name = time() . '_' . $_FILES['image']['name'];

        $destination = ROOT_PATH . "/assets/images/" . $image1_name;

        $result = move_uploaded_file($_FILES['image1']['tmp_name'], $destination);

        if ($result) {
           $_POST['image1'] = $image1_name;

        } else {
            array_push($errors, "Failed to upload image");
        }
    } else {
       array_push($errors, "Post image required");
    }


What I have tried:

I have tried using other variables
Posted
Updated 10-Jul-20 23:17pm
Rate this:
Please Sign up or sign in to vote.

Solution 1

You declared $image_name but used $image1_name
It also looks like you forgot your semicolon on line 7.

if (isset($_POST['add-post'])) {
    adminOnly();
    $errors = validatePost($_POST);

    ($_FILES['image']['name']);
        $image_name = time() . '_' . $_FILES['image']['name'];

        $destination = ROOT_PATH . "/assets/images/" . $image_name;

        $result = move_uploaded_file($_FILES['image1']['tmp_name'], $destination);

        if ($result) {
           $_POST['image1'] = $image1_name;

        } else {
            array_push($errors, "Failed to upload image");
        }
    } else {
       array_push($errors, "Post image d");
    }
   
v3
Rate this:
Please Sign up or sign in to vote.

Solution 2

You have declared
$image_name
yet you use
$image1_name
notice the 1 (one).
   

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100