Professional Documents
Culture Documents
Write A PHP Script To Create Photo Album Application and Call It Using Python
Write A PHP Script To Create Photo Album Application and Call It Using Python
- Create Album
- Upload Photos in Album
- Display Album in Gallery
→ Create Album
<?php
include_once "operation.php";
if(isset($_POST['btnAdd']))
$strName = trim(addslashes($_POST['txtName']));
$sqlQuery = " INSERT INTO album SET title = '$strName', status=1, created_at='".date('Y-m-
d')."', updated_at='".date('Y-m-d')."'";
fnFireQuery($sqlQuery);
$strListingUrl = 'album.php?m=1';
fnRedirectUrl($strListingUrl);
?>
<html>
<head>
<title>Add Album</title>
</head>
<body>
<div class="wrapper">
<div class="listing_container">
<h1>Add Album</h1>
2
W
<div class="add_album_form form_container">
<ul>
<li>
<label for="txtName">Name</label>
</li>
</ul>
<div class="button_container">
<button type="submit"
name="btnAdd"><span>Save Album</span></button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
Output:-
3
W
Operation.php :-
<?php
include_once "config.php";
function fnConnectDb()
return $objCon;
function fnFireQuery($sqlQuery)
$objCon = fnConnectDb();
function fnGetResults($sqlQuery)
$arrResults = array();
$resResults = fnFireQuery($sqlQuery);
$arrResults[] = $arrSpecResult;
return $arrResults;
3
W
function fnRedirectUrl($strUrl)
if(!headers_sent())
header("Location:".$strUrl);
exit;
else
?>
<script type="text/javascript">
</script>
<?php
exit;
function fnPhotoAlbum($intAlbumId)
$arrAlbum = fnGetResults($sqlQuery);
$arrSpecAlbum = $arrAlbum[0];
return trim($arrSpecAlbum['title']);
3
W
return 'NA';
?>
Config.php:-
<?php
define('DB_HOST','localhost');
define('DB_USER','root');
define('DB_PASS','');
define('DB_NAME','stud_1');
define("SITE_URL","http://localhost/php_practice/Journal/q6_album/program6/");
//http://localhost/tybca/practical/program6/
?>
-Upload Photos :-
<?php
include_once "operation.php";
if(isset($_POST['btnAdd']))
/*echo '<pre>';
print_r($_POST);
print_r($_FILES);
die;*/
$strFileName = $_FILES['flPhoto']['name'];
$strFileToUpload = 'uploads/'.$strFileName;
3
W
move_uploaded_file($_FILES['flPhoto']['tmp_name'], $strFileToUpload);
$strName = trim(addslashes($_POST['txtName']));
$intAlbumId = trim(addslashes($_POST['cmbAlbum']));
fnFireQuery($sqlQuery);
$strListingUrl = 'album.php?m=4';
fnRedirectUrl($strListingUrl);
?>
<html>
<head>
<title>Add Photo</title>
</head>
<body>
<div class="wrapper">
<div class="listing_container">
<h1>Add Photo</h1>
<ul>
<li>
3
W
<label for="txtName">Title</label>
</li>
<li>
<label for="cmbAlbum">Album</label>
<select name="cmbAlbum"
id="cmbAlbum">
<?php
$arrAlbums =
fnGetResults($sqlQuery);
if(is_array($arrAlbums) &&
count($arrAlbums))
foreach($arrAlbums as
$key => $arrSpecAlbum)
?>
<option value="<?php
echo $arrSpecAlbum['id']; ?>"><?php echo $arrSpecAlbum['title']; ?></option>
<?php
?>
</select>
</li>
<li>
<label for="flPhoto">Photo</label>
3
W
<input type="file" class="input-control"
name="flPhoto" id="flPhoto" />
</li>
</ul>
<div class="button_container">
<button type="submit"
name="btnAdd"><span>Save Photo</span></button>
</div>
</form>
</div>
</div>
</div>
</body>
</html>
Output:-
Photo Gallery(Index.php)
<?php
include_once "operation.php";
?>
<html>
<head>
3
W
<title>Photo Gallery</title>
</head>
<body>
<div class="button_container">
</div>
<div class="photo_gallery_container">
<h1>Photo Gallery</h1>
<div class="listing">
<ul>
<?php
$arrPhotos = fnGetResults($sqlQuery);
$strPhotoName =
$arrSpecPhoto['photo'];
$strPhotoUrl =
SITE_URL.'uploads/'.$strPhotoName;
$strTitle = trim($arrSpecPhoto['title']);
?>
<li>
3
W
</li>
<?php
?>
</ul>
</div>
</div>
</div>
</body>
</html>
Gallery.py
#! D:\xampp\python.exe
import subprocess
arrOutput = script_response.splitlines();
strHtmlOutput = "".join(arrOutput);
3
W
print(strHtmlOutput);
Output:-