Example #1
0
function uploadImage($fileDir)
{
    //http://www.w3schools.com/php/php_file_upload.asp
    $target_dir = $_SERVER['DOCUMENT_ROOT'] . "/" . $fileDir . "/img/";
    $target_file = $target_dir . $_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["submit"])) {
        $check = getimagesize($_FILES["fileToUpload"]["tmp_name"]);
        if ($check !== false) {
            echo "File is an image - " . $check["mime"] . ".";
            $uploadOk = 1;
        } else {
            echo "File is not an image.";
            $uploadOk = 0;
        }
    }
    // Check if file already exists
    if (file_exists($target_file)) {
        jsErrorAlert("Sorry, file already exists." . $target_file . ", fileDir= " . $fileDir);
        $uploadOk = 0;
    }
    // Check file size
    if ($_FILES["fileToUpload"]["size"] > 1000000) {
        jsErrorAlert("Sorry, your file is too large.");
        $uploadOk = 0;
    }
    // Allow certain file formats
    if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif" && $imageFileType != "JPG") {
        jsErrorAlert("Sorry, only JPG, JPEG, PNG & GIF files are allowed.");
        $uploadOk = 0;
    }
    // Check if $uploadOk is set to 0 by an error
    if ($uploadOk == 0) {
        jsErrorAlert("Sorry, your file was not uploaded.");
        // if everything is ok, try to upload file
    } else {
        if (move_uploaded_file($_FILES["fileToUpload"]["tmp_name"], $target_file)) {
            echo "The file " . basename($_FILES["fileToUpload"]["name"]) . " has been uploaded." . " to " . $target_dir;
        } else {
            echo "Sorry, there was an error uploading your file:" . $target_file . " to: " . $target_dir;
        }
    }
    if ($uploadOk == 1) {
        return $_FILES["fileToUpload"]["name"];
    } else {
        return FALSE;
    }
}
Example #2
0
 }
 if (!isset($_POST['bullet1']) || $_POST['bullet1'] === '') {
     $ok = false;
     jsErrorAlert("Required field missing.");
 } else {
     $bullet1 = $_POST['bullet1'];
 }
 if (!isset($_POST['bullet2']) || $_POST['bullet2'] === '') {
     $ok = false;
     jsErrorAlert("Required field missing.");
 } else {
     $bullet2 = $_POST['bullet2'];
 }
 if (!isset($_POST['bullet3']) || $_POST['bullet3'] === '') {
     $ok = false;
     jsErrorAlert("Required field missing.");
 } else {
     $bullet3 = $_POST['bullet3'];
 }
 // Connect to the DB
 $db = new mysqli('localhost', 'adamvh99_admin', 'apv0703', 'adamvh99_darboy');
 /* check connection */
 if ($db->connect_errno) {
     printf("Connect failed: %s\n", $db->connect_error);
     exit;
 } else {
     mysqli_autocommit($db, FALSE);
     $sql = sprintf("\n\t\t\tUPDATE modal \n\t\t\tSET heading='%s', genDesc='%s', vendorLink='%s', bullet1='%s', bullet2='%s', bullet3='%s'\n\t        WHERE imgPath='%s'", mysqli_real_escape_string($db, $heading), mysqli_real_escape_string($db, $genDesc), mysqli_real_escape_string($db, $webLink), mysqli_real_escape_string($db, $bullet1), mysqli_real_escape_string($db, $bullet2), mysqli_real_escape_string($db, $bullet3), $modalToUpdate);
     mysqli_query($db, $sql);
     echo '<p>Query complete</p>' . $sql;
     if ($db->query($sql) === TRUE && $basePath !== FALSE) {
Example #3
0
        exit;
    } else {
        mysqli_autocommit($db, FALSE);
        $sql = sprintf("INSERT INTO jobs (title, description) \n        VALUES (\n          '%s', '%s'\n        )", mysqli_real_escape_string($db, $title), mysqli_real_escape_string($db, $description));
        if ($db->query($sql) === TRUE) {
            jsErrorAlert("New record created successfully");
            mysqli_commit($db);
        } else {
            mysqli_rollback($db);
            jsErrorAlert("Error: " . $sql . "<br>" . $db->error);
        }
    }
    mysqli_close($db);
    header('Location: ' . $_SERVER['HTTP_REFERER']);
} else {
    jsErrorAlert("Something was wrong with your form");
}
?>
	<div class="row row-centered">
		<div class="col-lg-6 col-xs-10 col-centered">
			<div class="panel panel-info">
				<div class="panel-heading">
					<h3>Add New User</h3>
				</div>
				<div class="panel-body">
					<form method="post" action="">
						<label for='title'>Job Title:</label>
					    	<input type='text' name='title' class='userInput form-control' required value=''>
					    
					    <label for="description">Job Description:</label>
					   		<input type="text" name="description" class="userInput form-control" value="">