Creating a basic php file upload with mysql

I don’t usually think deep in making programs. Mostly, I just follow the basics and find the commands and compile it to make the program.

  1. Google the Create the MYSQL command function to connect to the database

http://www.w3schools.com/php/php_mysql_connect.asp


<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";
?>

2. Google the upload command function and compile it with the mysql connect function

http://www.w3schools.com/php/php_file_upload.asp


<?php
$servername = "localhost";
$username = "username";
$password = "password";

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
} 
echo "Connected successfully";

$target_dir = "uploads/";
$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["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;
    }
}
?>
<!DOCTYPE html>
<html>
<body>

<form action="upload.php" method="post" enctype="multipart/form-data">
    Select image to upload:
    <input type="file" name="fileToUpload" id="fileToUpload">
    <input type="submit" value="Upload Image" name="submit">
</form>

</body>
</html>


From that we created a simple mysql connect with php file upload.

OOP class pagination PHP

<?
/*
* Developer: Rex Adrivan
* Description: OOP pagination class
*/

class Pagination{
function Paginate($values,$per_page){
$total_values = count($values);

if(isset($_GET['page'])){
$current_page = $_GET['page'];
}else{
$current_page = 1;
}
$counts = ceil($total_values / $per_page);
$param1 = ($current_page - 1) * $per_page;
$this->data = array_slice($values,$param1,$per_page);

for($x=1; $x<= $counts; $x++){
$numbers[] = $x;
}
return $numbers;
}
function fetchResult(){ 
$resultsValues = $this->data;
return $resultsValues;
}
}


// Sample Usage

$pag = new Pagination();
$data = array("Hello","Rex","Prosper","Adrivan","Hehe");
$numbers = $pag->Paginate($data,2);
$result = $pag->fetchResult();
foreach($result as $r){
echo '<div>'.$r.'</div>';

}

foreach($numbers as $num){ 
echo '<a href="classpagination.php?page='.$num.'">'.$num.'</a>';
}



?>


Aligning DIV tags (Floating divs)

A beginner’s guide to DIV alignment.

This part is where I stuck up on studying design. I was about to give up until I saw this video (woooh thanks).

In making a cool website design you must know how div tag works since HTML5 is focused on <DIV> tags and we use this for Jquery purposes. <DIV> tags is my key in learning Jquery and CSS3. I find this tutorial useful cause like you I’m also confused on how the alignment of DIV tags work and how it affects CSS3 designs. ( while in Css3 we can use any tags we want.)

If you are new to Web development don’t be confused of <table> and <div> .  Modern codes doesn’t use <table> on design.

<table> is good on displaying of rectilinear data of arbitrary row(s) and/or column(s) and it should not be used for layouting purposes.

Facebook Auto tag and upload Photo

$args = array( ‘message’ => ‘Message’, ‘image’ => ‘@’ . realpath($path_to_image), ‘tags’ => array( array( ‘tag_uid’=> $friend1_uid, ‘x’ => $x1, ‘y’ => $y1, ), array( ‘tag_uid’ => $friend2_uid, ‘x’ => $x2, ‘y’ => $y2, ),/*…*/ ), ); $data = $facebook->api(‘/me/photos’, ‘post’, $args);
Where $facebook is initialized Facebook PHP SDK object. $data[‘id’] is id of uploaded photo.

Notes: 1. fileUpload option has to be set when initializing Facebook object:

$facebook = new Facebook(array( /*..*/ ‘fileUpload’ => true, ));