jueves, 24 de septiembre de 2015

Returning JSON from a PHP Script

<?php
header('Content-Type: application/json');
echo json_encode(array( 'status' => 'success', 'uniqueid' => 1111 ));

?>

http://php.net/manual/en/function.json-encode.php
http://stackoverflow.com/questions/4064444/returning-json-from-a-php-script

domingo, 20 de septiembre de 2015

PHP UPLOAD Error Messages Explained

 Messages Explained ¶

PHP returns an appropriate error code along with the file array. The error code can be found in the error segment of the file array that is created during the file upload by PHP. In other words, the error might be found in $_FILES['userfile']['error'].
UPLOAD_ERR_OK
Value: 0; There is no error, the file uploaded with success.
UPLOAD_ERR_INI_SIZE
Value: 1; The uploaded file exceeds the upload_max_filesize directive in php.ini.
UPLOAD_ERR_FORM_SIZE
Value: 2; The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.
UPLOAD_ERR_PARTIAL
Value: 3; The uploaded file was only partially uploaded.
UPLOAD_ERR_NO_FILE
Value: 4; No file was uploaded.
UPLOAD_ERR_NO_TMP_DIR
Value: 6; Missing a temporary folder. Introduced in PHP 5.0.3.
UPLOAD_ERR_CANT_WRITE
Value: 7; Failed to write file to disk. Introduced in PHP 5.1.0.
UPLOAD_ERR_EXTENSION
Value: 8; A PHP extension stopped the file upload. PHP does not provide a way to ascertain which extension caused the file upload to stop; examining the list of loaded extensions with phpinfo() may help. Introduced in PHP 5.2.0.

miércoles, 9 de septiembre de 2015

Simple MYSQL update script

update script

<?php


require("setting.php");
$link = mysqli_connect($setting["host"],$setting["username"],$setting["password"],$setting["db"]);

/* check connection */
if (mysqli_connect_errno()) {
    printf("Connect failed: %s\n", mysqli_connect_error());
    exit();
}


$query = "update users set comment ='viewed' where id ='1'";


if ($result = mysqli_query($link, $query)) {

   echo " Update OK ";

}
else {

printf(" failed: %s\n", mysqli_error($link));

}
mysqli_close($link);
?>








////Setting Sscript

<?php

//db conection settings
$setting=array("username"=>"root","password"=>"113","host"=>"127.0.0.1","db"=>"users");



?>


sábado, 5 de septiembre de 2015

Uploading multiple files

Example #1 Uploading multiple files
<?php
$uploads_dir 
'/uploads';
foreach (
$_FILES["pictures"]["error"] as $key => $error) {
    if (
$error == UPLOAD_ERR_OK) {
        
$tmp_name $_FILES["pictures"]["tmp_name"][$key];
        
$name $_FILES["pictures"]["name"][$key];
        
move_uploaded_file($tmp_name"$uploads_dir/$name");
    }
}
?>

Notes ¶

Note:
move_uploaded_file() is both safe mode and open_basedir aware. However, restrictions are placed only on the destination path as to allow the moving of uploaded files in which filename may conflict with such restrictions. move_uploaded_file() ensures the safety of this operation by allowing only those files uploaded through PHP to be moved.
Warning
If the destination file already exists, it will be overwritten.