Exemplo n.º 1
0
        }
        // Allow certain file formats
        if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
            $message = "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
            $uploadOk = 0;
        }
        // Check if $uploadOk is set to 0 by an error
        if ($uploadOk == 0) {
            $message = $message . "Sorry, your file was not uploaded.";
            // if everything is ok, try to upload file
        } else {
            if (move_uploaded_file($_FILES["imageToUpload"]["tmp_name"], $target_file)) {
                $message = "The file " . basename($_FILES["imageToUpload"]["name"]) . " has been uploaded.";
                //create ad and insert into database
                $ad = new Ad(NULL, $user_id, Input::get('name'), Input::get('description'), Input::get('price'), $target_file, Input::get('location'), Input::get('zip'), Input::get('make'), Input::get('model'), Input::get('size'), Input::get('condition'));
                $ad->insert();
                $message = "You have successfully submitted your ad, with new image.";
                $id = $ad->id;
            } else {
                $message = "Sorry, there was an error uploading your file.";
            }
        }
    } else {
        $ad = new Ad(Input::get('id'), $user_id, Input::get('name'), Input::get('description'), Input::get('price'), Input::get('image_url'), Input::get('location'), Input::get('zip'), Input::get('make'), Input::get('model'), Input::get('size'), Input::get('condition'));
        $ad->update();
        $message = "You have successfully updated your ad.";
        $id = $ad->id;
    }
} else {
    $id = Input::get('id');
}