How can I skip the Image upload here at php?

Question

I have this form which uploads a title, body, url and image url to my website. find it at: http://royvanoeteren.nl/wieisroy/editdata?page_ID=63

I have the problem that when I don't want to upload an image again, so only edit the text, I get an error that says: Warning: getimagesize(): Filename cannot be empty in /usr/www/vanohosting/public_royvanoeteren/models/wieisroy.php on line 122

As you see in the code under this text, I check if the addedImage button isn't pressed, which isn't pressed. So you would expect that the code goes to the point where the else begins

<?php
public function saveEditedData(){
    $post = filter_input_array(INPUT_POST, FILTER_SANITIZE_STRING);
    if($post['submitSave']){
        if($post['titel'] == "" || $post['body'] == "" || $post['link'] == ""){
            Messages::setMsg('Vul a.u.b alle velden in!', 'error');
            return;
        }
        if(!(isset($post['addedImage']))){
            $this->query('UPDATE roy SET title=:title, body=:body, link=:link, image=:image WHERE id=:pageID;');
            $this->bind(':title', $post['titel']);
            $this->bind(':body', $post['body']);
            $this->bind(':link', $post['link']);
            $this->bind(':pageID', $_GET['page_ID']);
            $this->bind(':image', $target_file_Site);
            $this->execute();
            Messages::setMsg('Successvol bewerkt!','succesMsg');
            //Verify
            if($this->lastInsertId()){
                //Redirect
                header('location: '.ROOT_URL. 'wieisroy');
            }
        } else {
            $target_dir = "/usr/www/vanohosting/public_royvanoeteren/models/uploads/";
            $target_dir_Site = "http://www.royvanoeteren.nl/models/uploads/";
            $target_file_Site = $target_dir_Site . basename($_FILES["fileToUpload"]["name"]);
            $target_file = $target_dir . basename($_FILES["fileToUpload"]["name"]);
            $uploadOk = 1;
            $imageFileType = pathinfo($target_file,PATHINFO_EXTENSION);
            // Check if image file is a actual image or fake image
            if(isset($post["submitSave"]) && isset($post['addedImage'])) {
                $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
                if($check !== false) {
                    Messages::setMsg("File is an image - " . $check["mime"] . ".",'succesMsg');
                    $uploadOk = 1;
                } else {
                    Messages::setMsg("File is not an image.",'error');
                    $uploadOk = 0;
                }
            }
            // Check if file already exists
            if (file_exists($target_file)) {
                Messages::setMsg("Sorry, file already exists.",'error');
                $uploadOk = 0;
            }

            // Check file size
            if ($_FILES["fileToUpload"]["size"] > 500000) {
                Messages::setMsg("Sorry, your file is too large.",'error');
                $uploadOk = 0;
            }

            // Allow certain file formats
            if($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg"
            && $imageFileType != "gif" ) {
                Messages::setMsg("Sorry, only JPG, JPEG, PNG & GIF files are allowed.",'error');
                $uploadOk = 0;
            }

            // Check if $uploadOk is set to 0 by an error
            if ($uploadOk == 0) {
                Messages::setMsg("Sorry, your file was not uploaded.",'error');
                // if everything is ok, try to upload file
            } else {
                if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
                    Messages::setMsg("The file ". basename( $_FILES["fileToUpload"]["name"]). " has been uploaded.", 'succesMsg');
                    //UPDATE DATA IN SQL
                    $this->query('UPDATE roy SET title=:title, body=:body, link=:link, image=:image WHERE id=:pageID;');
                    $this->bind(':title', $post['titel']);
                    $this->bind(':body', $post['body']);
                    $this->bind(':link', $post['link']);
                    $this->bind(':pageID', $_GET['page_ID']);
                    $this->bind(':image', $target_file_Site);
                    $this->execute();
                    Messages::setMsg('Successvol bewerkt!','succesMsg');
                    //Verify
                    if($this->lastInsertId()){
                        //Redirect
                        header('location: '.ROOT_URL. 'wieisroy');
                    }
                } else{
                    Messages::setMsg($errors[0], 'error');
                }
            }
        }
    }
}
?>

I expected that with this if & else the problem of empty filename error would be fixed, but no still getting an error. Anybody know what I'm doing wrong? the file can be found at: https://gist.github.com/anonymous/1b80bc072e9684eac5634b2048311df7


Show source
| pdo   | php   | image-uploading   2017-01-06 00:01 0 Answers

Answers to How can I skip the Image upload here at php? ( 0 )

Leave a reply to - How can I skip the Image upload here at php?

◀ Go back