First in php.ini file enable: extension=php_soap.dll
file url:http://localhost/soap/Db.php
<?php
class Db {
private $host = "localhost";
private $user = "root";
private $pass = "";
private $db = "webservice";
private $mysql;
public function __construct(){
$this->mysql = mysql_connect($this->host,$this->user,$this->pass);
if (! $this->mysql) {
die('Connect Error :'.mysql_error());
}else{
mysql_select_db($this->db);
}
}
public function insert($data){
$path = null;
$sql = "SELECT g.id, g.thumb_path,g.title,g.active,g.web_section_id,s.section_name,g.web_category_id,c.category_name FROM web_image_gallerys g LEFT JOIN web_sections s ";
$sql .= "ON g.web_section_id = s.id LEFT JOIN web_categorys c ";
$sql .= "ON g.web_category_id = c.id ";
if($data['web_section_id'] && $data['web_category_id']){
$sql .= "where g.web_section_id={$data['web_section_id']} and g.web_category_id={$data['web_category_id']} order by g.id desc limit 1";
}else if($row['section_name'] && ! $row['category_name']){
$sql .= "where g.web_section_id={$data['web_section_id']} order by g.id desc limit 1";
}
$q = mysql_query($sql,$this->mysql);
$pathInfo = mysql_fetch_object($q, 'Db');
if($data['web_section_id'] && $data['web_category_id']){
$path = $_SERVER['DOCUMENT_ROOT']."/soap/images/upload/gallery/{$pathInfo->section_name}/{$pathInfo->category_name}/{$data['file_name']}";
}else if($row['section_name'] && ! $row['category_name']){
$path = $_SERVER['DOCUMENT_ROOT']."/soap/images/upload/gallery/{$pathInfo->section_name}/{$data['file_name']}";
}
if(! copy($data['tmp_path'],$path)) {
return false;
}
$sqlIn ="INSERT INTO web_image_gallerys (id,title, thumb_path,web_section_id,web_category_id,active) VALUES ('','$data[fup_title]','$data[file_name]','$data[web_section_id]','$data[web_category_id]','$data[fup_active]')";
$insert = mysql_query($sqlIn,$this->mysql);
if($insert){
mysql_close($this->mysql);
return true;
}else{
mysql_close($this->mysql);
return false;
}
}
public function update($data){
$path = null;
$sql = "SELECT g.id, g.thumb_path,g.title,g.active,g.web_section_id,s.section_name,g.web_category_id,c.category_name FROM web_image_gallerys g LEFT JOIN web_sections s ";
$sql .= "ON g.web_section_id = s.id LEFT JOIN web_categorys c ";
$sql .= "ON g.web_category_id = c.id ";
if($data['web_section_id'] && $data['web_category_id']){
$sql .= "where g.web_section_id={$data['web_section_id']} and g.web_category_id={$data['web_category_id']} order by g.id desc limit 1";
}else if($row['section_name'] && ! $row['category_name']){
$sql .= "where g.web_section_id={$data['web_section_id']} order by g.id desc limit 1";
}
$q = mysql_query($sql,$this->mysql);
$pathInfo = mysql_fetch_object($q, 'Db');
if($data['web_section_id'] && $data['web_category_id']){
$path = $_SERVER['DOCUMENT_ROOT']."/soap/images/upload/gallery/{$pathInfo->section_name}/{$pathInfo->category_name}/{$data['file_name']}";
}else if($row['section_name'] && ! $row['category_name']){
$path = $_SERVER['DOCUMENT_ROOT']."/soap/images/upload/gallery/{$pathInfo->section_name}/{$data['file_name']}";
}
if(! $data['tmp_path'] && ! copy($data['tmp_path'],$path)) {
return false;
}
$sql = "UPDATE web_image_gallerys\n";
$sql .= "SET title='$data[fup_title]',\n";
$sql .= "thumb_path='$data[file_name]',\n";
$sql .= "web_section_id='$data[web_section_id]',\n";
$sql .= "web_category_id='$data[web_category_id]',\n";
$sql .= "active='$data[fup_active]'\n";
$sql .= "WHERE id='$data[id]'";
$update = mysql_query($sql,$this->mysql);
if($update){
mysql_close($this->mysql);
return true;
}else{
mysql_close($this->mysql);
return false;
}
}
public function delete($id){
$sql = "DELETE FROM web_image_gallerys WHERE id=$id";
if(mysql_query($sql,$this->mysql)){
return true;
}else{
return false;
}
}
public function getAll(){
$path = null;
$sql = "SELECT g.id, g.thumb_path,g.title,g.active,g.web_section_id,s.section_name,g.web_category_id,c.category_name FROM web_image_gallerys g LEFT JOIN web_sections s ";
$sql .= "ON g.web_section_id = s.id LEFT JOIN web_categorys c ";
$sql .= "ON g.web_category_id = c.id ";
$sql .= "where 1=1 order by g.id desc";
$q = mysql_query($sql,$this->mysql);
$result = array();
while($row = mysql_fetch_array($q)) {
if($row['section_name'] && $row['category_name']){
$path ='http://localhost/soap/images/upload/gallery/'.$row['section_name'].'/'.$row['category_name'].'/'.$row['thumb_path'];
}else if($row['section_name'] && ! $row['category_name']){
$path = 'http://localhost/soap/images/upload/gallery/'.$row['section_name'].'/'.$row['thumb_path'];
}
$result[] = array(
'id'=>$row['id'],
'title'=>$row['title'],
'section_name'=>$row['section_name'],
'category_name'=>$row['category_name'],
'thumb_path'=>$path,
'active'=>$row['active']
);
}
mysql_close($this->mysql);
return $result;
}
public function getById($id){
$path = null;
$sql = "SELECT g.id, g.thumb_path,g.title,g.active,g.web_section_id,s.section_name,g.web_category_id,c.category_name FROM web_image_gallerys g LEFT JOIN web_sections s ";
$sql .= "ON g.web_section_id = s.id LEFT JOIN web_categorys c ";
$sql .= "ON g.web_category_id = c.id ";
$sql .= "where g.id={$id} order by g.id desc";
$q = mysql_query($sql,$this->mysql);
$result = array();
while($row = mysql_fetch_array($q)) {
if($row['section_name'] && $row['category_name']){
$path ='http://localhost/soap/images/upload/gallery/'.$row['section_name'].'/'.$row['category_name'].'/'.$row['thumb_path'];
}else if($row['section_name'] && ! $row['category_name']){
$path = 'http://localhost/soap/images/upload/gallery/'.$row['section_name'].'/'.$row['thumb_path'];
}
$result[] = array(
'id'=>$row['id'],
'title'=>$row['title'],
'web_section_id'=>$row['web_section_id'],
'section_name'=>$row['section_name'],
'category_name'=>$row['category_name'],
'web_category_id'=>$row['web_category_id'],
'thumb_path'=>$path,
'active'=>$row['active']
);
}
mysql_close($this->mysql);
return $result[0];
}
}
?>
file url:http://localhost/soap/server.php
<?php include __dir__."/Db.php"; try { $server = new SOAPServer(NULL,array( 'uri' => 'http://localhost/soap/server.php' ) ); $server->setClass('Db'); $server->handle(); }catch (SOAPFault $f) { print $f->faultstring; exit; } //print_r($server); ?>
file url:http://localhost/soapclient/client.php
<?php $client = new SoapClient(null, array( 'location' => "http://localhost/soap/server.php", 'uri'=> "urn://localhost/soap/server.php", 'trace'=> 1 ) ); //print_r($client); ?>
file url:http://localhost/soapclient/list.php
<?php <?php include __dir__.'/client.php'; $requestIns = $client->__soapCall("getAll", array()); //print_r($requestIns);die; ?> <html> <title>upload</title> <head > <link href="bootstrap-3.3.7/dist/css/bootstrap.css" rel="stylesheet" type="text/css"> <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script> function previewFile() { var preview = document.querySelector('img'); var file = document.querySelector('input[type=file]').files[0]; var reader = new FileReader(); reader.addEventListener("load", function () { preview.src = reader.result; }, false); if (file) { var dd = reader.readAsDataURL(file); } } </script> <script> jQuery(function(){ jQuery('#ukm').change( function(event) { var tmppath = URL.createObjectURL(event.target.files[0]); jQuery("img").fadeIn("fast").attr('src',tmppath); alert(json.stringfy(event.target.files[0])); }); }); </script> </head> <body> <div class="panel panel-success"> <div class="panel-heading">New Gallery</div> <div class="panel-body"> <?php if( $requestIns){ ?> <table class="table"> <caption> By Built-in SoapClient</caption> <tr> <th>Title</th> <th>Image</th> <th>action</th> </tr> <?php foreach($requestIns as $resp){ echo'<tr>'; echo'<td>'.$resp['title'].'</td>'; echo'<td><img style="width:100px;" src="'.$resp['thumb_path'].'"></td>'; $edit ="http://localhost/soapclient/edit.php?id=".$resp['id'].""; $delete ="http://localhost/soapclient/insertUpdate.php?delete=d&id=".$resp['id'].""; $add ="http://localhost/soapclient/upload.php"; echo"<td><a class='btn btn-sm btn-primary' href=".$edit.">edit</a>"; echo"<a class='btn btn-sm btn-warning' href=".$delete.">delete</a>"; echo"<a class='btn btn-sm btn-warning' href=".$add.">Add</a></td>"; echo'</tr>'; } echo'<table>'; } ?> </div> </div> </body> </html>
file url:http://localhost/soapclient/edit.php
<?php include __dir__.'/client.php'; $galleryIns = null; ?> <html> <title>upload</title> <head> <link href="bootstrap-3.3.7/dist/css/bootstrap.css" rel="stylesheet" type="text/css" > <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script> function previewFile() { var preview = document.querySelector('img'); var file = document.querySelector('input[type=file]').files[0]; var reader = new FileReader(); reader.addEventListener("load", function () { preview.src = reader.result; }, false); if (file) { var dd = reader.readAsDataURL(file); getFilePath(); } } function getFilePath(){ var file = document.querySelector('input[type=file]').files[0]; var filePath=jQuery('#ukm').val(); var path = (window.URL || window.webkitURL).createObjectURL(file); const reader = new FileReader(); alert(reader.readAsText(path)); } </script> <script> jQuery(function(){ jQuery('#ukm').change( function(event) { var tmppath = URL.createObjectURL(event.target.files[0]); jQuery("img").fadeIn("fast").attr('src',tmppath); alert(json.stringfy(event.target.files[0])); }); }); </script> </head> <body> <?php $id = $_GET['id']; $galleryIns = $client->__soapCall("getById", array('id'=>$id)); if($galleryIns){ ?> <div class="panel panel-success"> <div class="panel-heading">Update Gallery</div> <div class="panel-body"> <form class="form-horizontal" role="form" method="POST" action="http://localhost/soapclient/insertUpdate.php" enctype="multipart/form-data"> <div class="form-group col-md-4"> <label>Web Section</label> <div> <select name="web_section_id" class="form-control" value=""> <option value="39">Image Gallery</option> </select> </div> </div> <div class="form-group col-md-4"> <label>Web Category</label> <div> <select name="web_category_id" class="form-control" value=""> <option value="20">Image Gallery</option> </select> </div> </div> <div class="col-md-12 col-lg-12 cls"> <div class="form-group col-md-4"> <label>Upload File</label> <div> <input type="file" name="fup_ukmFile" id="ukm" accept=".gif,.jpg,.jpeg,.png" onchange="previewFile()"> <img src="" height="200" alt="Image preview..."> </div> </div> <div class="form-group col-md-4"> <label>Title</label> <div> <input type="hidden" name="id" value=""/> <input type="text" pattern="^[A-Za-z_-\\]{5,50}" class="form-control" id="fup_title" name="fup_title" value=""> </div> </div> <div class="form-group col-md-4"> <label>Is Publish</label> <div> <select name="fup_active" class="form-control" value=""> <option value="1">Publish</option> <option value="0">Unpublish</option> </select> </div> </div> </div> <div class="form-group"> <div class="col-md-12" align="center"> <input type="hidden" name="update" value="update"/> <button type="submit" class="btn btn-primary"> Submit </button> </div> </div> </form> </div> </div> </body> <?php } ?> </html>
file url:http://localhost/soapclient/insertUpdate.php
<?php include __dir__.'/client.php'; $requestIns = null; if(@$_POST['update']=='update'){ $data = array( 'id'=>$_POST['id'], 'web_category_id'=>$_POST['web_category_id'], 'web_section_id'=>$_POST['web_section_id'], 'fup_ukmFile'=>$_FILES['fup_ukmFile']["tmp_name"], 'tmp_path'=>$_FILES['fup_ukmFile']["tmp_name"], 'file_name'=>$_FILES['fup_ukmFile']["name"], 'type'=>$_FILES['fup_ukmFile']["type"], 'size'=>$_FILES['fup_ukmFile']["size"], 'fup_title'=>$_POST['fup_title'], 'fup_active'=>$_POST['fup_active'] ); if($client->__soapCall("update", [$data])){ return header("Location: http://localhost/soapclient/list.php", true, 301); }else{ header("Location: http://localhost/soapclient/edit.php?id=".$_POST['id']."", true, 301); } }else if($_POST['insert']=='insert'){ $data = array( 'web_category_id'=>$_POST['web_category_id'], 'web_section_id'=>$_POST['web_section_id'], 'fup_ukmFile'=>$_FILES['fup_ukmFile']["tmp_name"], 'tmp_path'=>$_FILES['fup_ukmFile']["tmp_name"], 'file_name'=>$_FILES['fup_ukmFile']["name"], 'type'=>$_FILES['fup_ukmFile']["type"], 'size'=>$_FILES['fup_ukmFile']["size"], 'fup_title'=>$_POST['fup_title'], 'fup_active'=>$_POST['fup_active'] ); if($client->__soapCall("insert", [$data])){ return header("Location: http://localhost/soapclient/list.php", true, 301); }else{ header("Location: http://localhost/soapclient/upload.php", true, 301); } }else if($_GET['delete']=='d'){ if($client->__soapCall("delete",array('id'=>$_GET['id']))){ return header("Location: http://localhost/soapclient/list.php", true, 301); }else{ return header("Location: http://localhost/soapclient/list.php", true, 301); } } ?>
file url:http://localhost/soapclient/upload.php
<html> <title>upload</title> <head> <link href="bootstrap-3.3.7/dist/css/bootstrap.css" rel="stylesheet" type="text/css"> <script src="http://code.jquery.com/jquery-1.11.1.min.js"></script> <script> function previewFile() { var preview = document.querySelector('img'); var file = document.querySelector('input[type=file]').files[0]; var reader = new FileReader(); reader.addEventListener("load", function () { preview.src = reader.result; }, false); if (file) { var dd = reader.readAsDataURL(file); } } </script> <script> jQuery(function(){ jQuery('#ukm').change( function(event) { var tmppath = URL.createObjectURL(event.target.files[0]); jQuery("img").fadeIn("fast").attr('src',tmppath); alert(json.stringfy(event.target.files[0])); }); }); </script> </head> <body> <div class="panel panel-success"> <div class="panel-heading">New Gallery</div> <div class="panel-body"> <form class="form-horizontal" role="form" method="POST" action="http://localhost/soapclient/insertUpdate.php" enctype="multipart/form-data"> <div class="form-group col-md-4"> <label>Web Section</label> <div> <select name="web_section_id" class="form-control" value=""> <option value="39">Image Gallery</option> </select> </div> </div> <div class="form-group col-md-4"> <label>Web Category</label> <div> <select name="web_category_id" class="form-control" value=""> <option value="20">Image Gallery</option> </select> </div> </div> <div class="col-md-12 col-lg-12 cls"> <div class="form-group col-md-4"> <label>Upload File</label> <div> <input type="file" name="fup_ukmFile" id="ukm" accept=".gif,.jpg,.jpeg,.png" onchange="previewFile()"> <img src="" height="200" alt="Image preview..."> </div> </div> <div class="form-group col-md-4"> <label>Title</label> <div> <input type="text" pattern="^[A-Za-z_-\\]{5,50}" class="form-control" id="fup_title" name="fup_title" value=""> </div> </div> <div class="form-group col-md-4"> <label>Is Publish</label> <div> <select name="fup_active" class="form-control" value=""> <option value="1">Publish</option> <option value="0">Unpublish</option> </select> </div> </div> </div> <div class="form-group"> <div class="col-md-12" align="center"> <input type="hidden" name="insert" value="insert"/> <button type="submit" class="btn btn-primary"> Submit </button> </div> </div> </form> </div> </div> </body> </html>
Total : 20662
Today :41
Today Visit Country :