How to open an image from the database as a popup? - php

I have this script. I have searched dozens of questions on this site and none of them seem to work. However, none of the ones I saw are calling for the image from a database either, so that may be the issue.
My obejctive is to make it so this can open in the center of the screen as a popup instead of to another page or on top of the page as a link. Any help or guidance is appreciated.
I don't mind using java or css if that is what is needed, however I will tell you that my understanding of both is very small so far, but I'm learning
EDIT 2
I have tried to use lightbox but that didn't work at all. I also tried onclick="window.open... but that didn't work either. At best it opened a blank page in the corner of the window
Here is what I have
<img src="<?= $imageURL; ?>" width="350" />
EDIT
Here is the entire page script I have
<table width="100%" border="0" cellspacing="0" cellpadding="0" bgcolor="#000000">
<tr valign="top" align="left">
<td width="4%"><a style="text-decoration:none" href="/apppages/more.html"><img src="../appimg/arrow.png" width="108" height="68" border="0"></a></td>
<td width="96%" valign="middle"><a style="text-decoration:none" href="/apppages/more.html"> <font color="#CCCCCC" size="6" face="Verdana, Arial, Helvetica, sans-serif">More
Links Options</font></a></td>
</tr>
</table>
<p><br>
</p>
<p> <img src="header2.jpg" width="921" height="479"><br>
<font size="7"><br>
<a href="app-form.php" target="_blank"><font face="Verdana, Arial, Helvetica, sans-serif" color="#9999FF">TAP
HERE TO ADD YOUR SELFIE</font></a></font><br>
<br>
<?php
include 'config.php';
// Get images from the database
$query = $db->query("SELECT nameviewer, file_name FROM image ORDER BY uploaded_on DESC");
?> </p>
</div>
<table width="20%" border="1" cellspacing="0" cellpadding="0" align="center">
<?php
$i = 0;
while ($row = $query->fetch_assoc()){
$nameviewer = 'uploads/'.$row["nameviewer"];
$imageURL = 'uploads/'.$row["file_name"];
if ($i++ % 4 == 0) { // start new row before each group of 4
echo '<tr>';
}
?>
<td valign="top">
<div align="center"><img src="<?= $imageURL; ?>" width="350" /><br>
<font color='lightblue'> <b><font size="6"><?php echo htmlspecialchars($row["nameviewer"]); ?></font></b></font><br>
<font size="6"><i><font color="#999999">Tap The Pic To Expand</font></i></font>
</div>
</td>
<?php
if ($i % 4 == 0) { // end row after a group of 4
echo '</tr>';
}
}
if ($i % 4 != 0) { // end the last row if it wasn't an even multiple of 4
echo '</tr>';
}
?>
</table>

One of the ways is to use a jquery lightbox
First, add the necessary CSS and JS at the top of your script
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
<script type="text/javascript" src="https://www.jqueryscript.net/demo/Responsive-Touch-enabled-jQuery-Image-Lightbox-Plugin/dist/simple-lightbox.jquery.min.js"></script>
<link href='https://www.jqueryscript.net/demo/Responsive-Touch-enabled-jQuery-Image-Lightbox-Plugin/dist/simple-lightbox.min.css' rel='stylesheet' type='text/css'>
<link href='https://www.jqueryscript.net/demo/Responsive-Touch-enabled-jQuery-Image-Lightbox-Plugin/demo.css' rel='stylesheet' type='text/css'>
<link href="https://jquery.app/jqueryscripttop.css" rel="stylesheet" type="text/css">
Enclose your table containing the photos by <div class="gallery"> and </div>
Add the following block to trigger the lightbox script:
<script>
$(function(){
var gallery = $('.gallery a').simpleLightbox({navText: ['‹','›']});
});
</script>
Please further adjust the code if necessary to suit your needs.
See the Sandbox (based on your script and slightly amended) for a working example (check the source and you will be able to see that it is applying the above 3 steps) :
http://www.createchhk.com/SOanswers/sub6/testSO15Oct2022.html

Related

Create list of specific files in subdirectories

I have a structure:
[catalogues]
[catalogue-name-1]
[data_html]
name-1.html - table of posted values from another form
name-2.html - table of posted values from another form
name-3.html - table of posted values from another form
...
name-n.html - table of posted values from another form
catalogue-name-1.html
[catalogue-name-2]
catalogue-name-2.html
[catalogue-name-3]
catalogue-name-3.html
index.php
How shall I write the function in catalogue-name-?.html to have merged the content of all data_html-tables in one html-table in catalogue-name-?.html?
How shall I write the index.php to have listed all catalogue-name-?.html files as a list of links?
name-1
name-2
name-3
...
name-n
Thank you for the hints. There are 3 PHP files involved:
index.php - there is an entry form posting values into the work/data.php file, then values manipulated in it are saved in new HTML files in respective data_html folders to be then shown by work/preview.php. In data.php, there is about this code:
<?php
// directory names
$dir_catalogues = '../catalogues/';
$dir_catalogue = $dir_catalogues.$_POST['catalogue_name'];
$dir_html = $dir_catalogue.'/data_html/';
$dir_csv = $dir_catalogue.'/data_csv/';
//Check if the directory with the name already exists
//Create our directory if it does not exist
if (!is_dir($dir_catalogues)) {
mkdir($dir_catalogues);
echo "Directory ".$dir_catalogues." created<br>";
}
if (!is_dir($dir_catalogue)) {
mkdir($dir_catalogue);
echo "Directory ".$dir_catalogue." created<br>";
}
if (!is_dir($dir_html)) {
mkdir($dir_html);
echo "Directory ".$dir_html." created<br>";
}
if (!is_dir($dir_csv)) {
mkdir($dir_csv);
echo "Directory ".$dir_csv." created";
}
// file names
$img_name_html = $_POST['img_name'].'.html';
$img_name_csv = $_POST['img_name'].'.csv';
$catalogue_name = 'catalogue-'.$_POST['catalogue_name'].'.html';
// HTML file content
$html = '
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Images rights information</title>
<style>
...
</style>
</head>
<body>
<div class="wrapper">
<table cellpadding="5">
<th colspan="2">Image info</th>
<tr class="thumb_row""><td class="logo" colspan="2"><img class="img_thumb" src="'.$_POST['img_use_url'].'" alt="Thumbnail"><h3>'.$_POST['img_title'].'</h3></td></tr>
<tr><td width="140" class="lab">File name</td><td colspan="5">'.$_POST['img_name'].'</td></tr>
<tr><td width="140" class="lab">Description</td><td colspan="5">'.$_POST['img_description'].'</td></tr>
<tr><td width="140" class="lab">Source URL</td><td colspan="5">'.$_POST['img_source_url'].'</td></tr>
<tr><td width="140" class="lab">Image use URL</td><td colspan="5">'.$_POST['img_use_url'].'</td></tr>
<tr><td width="140" class="lab">Copyright owner</td><td colspan="5">'.$_POST['img_copyright_owner'].'</td></tr>
<tr><td width="140" class="lab">Author</td><td colspan="5">'.$_POST['img_author'].'</td></tr>
<tr><td width="140" class="lab">Author\'s URL</td><td colspan="5">'.$_POST['img_author_url'].'</td></tr>
<tr><td width="140" class="lab">License</td><td colspan="5">'.$_POST['img_license'].'</td></tr>
<tr><td width="140" class="lab">License Nr.</td><td colspan="5">'.$_POST['img_license_nr'].'</td></tr>
</table>
</div>
</body>
</html>';
......
// create catalogue HTML file
file_put_contents($dir_catalogue .'/'.$catalogue_name, $html, FILE_APPEND | LOCK_EX);
I made have achieved some progress (found and applied som working scripts). But I stuck at the following:
sofar I have in my code about this:
<!-- FILE HEADDINGS -->
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Images rights information</title>
<style>
*{font-family: arial, tahoma, verdana;}
.wrapper{width: 900px; margin:auto;box-sizing:border-box;}
table{width:100%}
th{font-size:2.2em; font-weight:bold;}
.thumb_row{background:#eee;}
td.logo, th{border-bottom:2px solid #999;}
.img_thumb{max_height: 180px; width:auto; margin: .2em; float:left;}
td.logo img{ float: left; margin-right:2em;}
td a img{border: 2px solid blue;}
td a:hover img{border: 2px solid orange;}
td.lab{font-weight:bold;vertical-align:top;}
td h3{font-size:2em; font-weight:bold}
</style>
</head>
<body>
<div class="wrapper">
<!-- FILE HEADDINGS END -->
<table cellpadding="5">
<th colspan="2">Image info</th>
<tr class="thumb_row"><td class="logo" colspan="2"><img class="img_thumb" src="'.$_POST['img_use_url'].'" alt="Thumbnail"><h3>'.$_POST['img_title'].'</h3></td></tr>
<tr><td width="140" class="lab">File name</td><td colspan="5">'.$_POST['img_name'].'</td></tr>
<tr><td width="140" class="lab">Description</td><td colspan="5">'.$_POST['img_description'].'</td></tr>
<tr><td width="140" class="lab">Source URL</td><td colspan="5">'.$_POST['img_source_url'].'</td></tr>
<tr><td width="140" class="lab">Image use URL</td><td colspan="5">'.$_POST['img_use_url'].'</td></tr>
<tr><td width="140" class="lab">Copyright owner</td><td colspan="5">'.$_POST['img_copyright_owner'].'</td></tr>
<tr><td width="140" class="lab">Author</td><td colspan="5">'.$_POST['img_author'].'</td></tr>
<tr><td width="140" class="lab">Author\'s URL</td><td colspan="5">'.$_POST['img_author_url'].'</td></tr>
<tr><td width="140" class="lab">License</td><td colspan="5">'.$_POST['img_license'].'</td></tr>
<tr><td width="140" class="lab">License Nr.</td><td colspan="5">'.$_POST['img_license_nr'].'</td></tr>
</table>
<!-- FILE FOOTER -->
</div>
</body>
</html>
// CSV file content
$csv = $_POST['catalogue_name'].'|'.$_POST['img_title'].'|'.$_POST['img_name'].'|'.$_POST['img_description'].'|'.$_POST['img_source_url'].'|'.$_POST['img_copyright_owner'].'|'.$_POST['img_author'].'|'.$_POST['img_author_url'].'|'.$_POST['img_license'].'|'.$_POST['img_license_nr'];
// create catalogue HTML file
file_put_contents($dir_catalogue .'/'.$catalogue_name.'.html', $html, FILE_APPEND | LOCK_EX);
file_put_contents($dir_catalogue .'/index.html', $html, FILE_APPEND | LOCK_EX);
// create catalogue CSV file
file_put_contents($dir_catalogue .'/'.$catalogue_name.'.csv', $csv, FILE_APPEND | LOCK_EX);
file_put_contents($dir_catalogue .'/index.csv', $csv, FILE_APPEND | LOCK_EX);
}
But the result is that the entire $html code is inserted into the catalog file (I want to have the "headings" added only in the beginning, the all individually saved tables, and the "footer" also always only on end of the HTML-catalog file.
The CSV output has all variables put into one endless line. I want to have each record in one line.

jquery not working on using pagination

Am just trying to show all the list in the pagination. am using datatable plugin's pagination on my file, pagination is working fine, in the list i have an image that have a function delete on click. in my pagination 1'st five records is shown . and the other five records shown on click next, delete function working properly on 1'st five record when i click on next than delete function stop it's working .
my code:-
<script>
var conf = jQuery.noConflict();
conf(document).ready(function(){
conf(".delete").on( "click", function() {
alert('adfasdfasd');
//alert(conf(this).attr("id"));
custid = conf(this).attr("id");
var r=confirm("Are you sure");
if (r==true)
{
var url = "<?php echo Mage::getBaseUrl();?>turnkey/index/deleteuser/";
conf.ajax({
type:"POST",
url:url,
data: { 'custid':custid},
success: function(msz){
alert(msz);
if(msz=="deleted") {
conf("#hidepro"+custid).hide("slow");
}
else {
//conf("#hidepro"+proid).hide();
alert("product cant be deleted");
}
//console.log("chal hun");
}
});
}
else
{
return false ;
}
});
});
</script>
and the pagination code is :-
<script type="text/javascript" charset="utf-8">
$(document).ready(function() {
$('#example').dataTable();
} );
</script>
<div id="container">
<div id="demo">
<table cellpadding="0" cellspacing="0" border="0" class="display" id="example" width="100%">
<thead>
<tr>
<th>Factory</th>
<th></th>
<th>Contact</th>
<th>URL</th>
<th>Remove</th>
</tr>
</thead>
<tbody>
<?php
foreach( $custemail as $custemail1 ) {
$customer = Mage::getModel("customer/customer");
$customer->setWebsiteId(Mage::app()->getWebsite()->getId());
$customer->loadByEmail($custemail1); //load customer by email id ?>
<tr class="odd gradeX" style=" border-bottom: 1px solid #FF0000;" id = "hidepro<?php echo $customer['entity_id'] ?>">
<td class="bodyText style4" ><a style=" color: #CC3300;float: left;margin-top: 42px !important;text-decoration: underline;" href="<?php echo Mage::getBaseUrl();?>turnkey/index/listuser?id=<?php echo $customer->getEntity_id();?>"><?php echo $customer->getFactory();?></a> </td>
<td class="bodyText style4">
<a href="<?php echo Mage::getBaseUrl();?>turnkey/index/listuser?id=<?php echo $customer->getEntity_id();?>">
<img style=" width:100px;height:100px;margin-bottom:5px ;" src = "http://lab.ghrix.com/turn-key-mart/media/<?php echo $customer->getUserImage();?>"></a>
</td>
<td class="bodyText style4" style="padding-top: 10px;">
<?php echo $customer->getFirstname();?><?php //echo $customer->getUser_address();?><br><?php echo $customer->getmobile();?><br><?php echo $customer->getEmail();?></td>
<td class="bodyText style4" style="float: left;margin-top: 42px !important;" >
<a target="_blank" style="color:#005580;" href="<?php echo $customer->getWebsite();?>"><?php echo $customer->getWebsite();?></a></td>
<td class="bodyText style4"><div style= "cursor:pointer;" class = "delete" id = "<?php echo $customer['entity_id'] ?>"><img width="60px" src="<?php echo $this->getSkinUrl('images/trash.jpg'); ?>"</div></td>
</tr>
<?php }?>
</tbody>
</table>
</div>
</div>
please suggest where mistake is happen.
Without a live example, I can't be sure, but try this:
replace
conf(".delete").on("click", function() ...
with:
conf(document).on("click", ".delete", function() ...
The reason is that conf(".delete") only attaches to elements available at the time the function is run. It might be that your dataTable plugin runs first, removes the extra elements, then the delete binder is run and only works on the first 5. The second method binds to the document, and checks each click to see if it matches the .delete selector. This used to be known as jQuery.live()

pagination in form php

i have this code :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<style>
body {
background-image: url(../images/paper_03.png);
}
form {
background-image: url(../images/paper_02.png);
}
</style>
</head>
<?php
require("../function.php");
// echo sizeof($_SESSION['liste']);
?>
<body >
<form name="log" method="post" style="position: absolute; top:50px; left: 320px; width: 600px; height: 100%;" >
<table BORDER=2 style="position: relative; top:15px; left: 3px;" >
<TR>
<TH style="width:100px"><font color="blue">Date</font></TH>
<TH style="width:400px"><font color="blue">Location</font></TH>
<TH style="width:400px"><font color="blue">Job Title</font></TH>
<TH style="width:300px"><font color="blue">Company</font></TH>
</TR>
<?php
session_start();
for($i=0;$i<sizeof($_SESSION['liste']);$i++){
?>
<TR>
<td ><center><label><?php echo $_SESSION['liste'][$i]['date']; ?></label></center></td>
<td ><label><?php echo $_SESSION['liste'][$i]['region'].','.$_SESSION['liste'][$i]['city'].','.$_SESSION['liste'][$i]['state']; ?></label></td>
<td ><center><label><?php echo $_SESSION['liste'][$i]['title']; ?></label></center></td>
<td ><center><label><?php echo $_SESSION['liste'][$i]['comapany_name']; ?></label></center></td>
</TR>
<?php
}
?>
</table>
</form>
</body>
</html>
i have a form i want that every 10 results be displayed togother ie add the pagination to my form with two icons ( next, previous ).
can i do this only with php?
do i need ajax in this work?
Pass a $liststart value in as a parameter to your code (get it with $liststart = $_REQUEST['liststart']).
Then adjust your loop to loop from $liststart to $liststart+10.
Make a button that onClick, goes to your code above with the new $liststart value. for example for the 'next' button on the first page, use echo "' onClick='location.href=\"yourcodeabove.php?liststart=".$liststart+10."\";'>";
or if you prefer, you could do it without javascript by making the next and prev buttons their own forms. like this:
<FORM METHOD="LINK" ACTION="yourcodeabove.php?liststart="<?php $liststart+10 ?>">
<INPUT TYPE="submit" VALUE="next->">
</FORM>
close out your other form first (which doesn't look like it needs to be a form actually... could be a div just as well). forms usually have 'actions' and are submitted with buttons but since you'll have 2 buttons (next and prev) each could be their own form with either the javascript onClick or the form method.
If you use mysql this should work:
$page = $_GET['page'];
$query = mysql_query("SELECT * FROM some_table LIMIT $page, 10");
And do some work with $query variable, your links should be something like this:
Next

PHP. session_start() [function.session-start]: Cannot send session cookie error

Im having problem in my web where it works perfectly on my local server which is a WAMPSERVER i can run my website completely but after adding to the web server it give me error saying
Warning: session_start() [function.session-start]: Cannot send session cookie - headers already sent by (output started at /home/multisl/public_html/udrivetest/index.php:2) in /home/multisl/public_html/udrivetest/init.php on line 4
init.php
<?php
ob_start();
session_start();
mysql_connect("localhost","***","***");
mysql_select_db('****');
include 'function/user.func.php';
include 'function/car.func.php';
include 'function/image.func.php';
?>
header1.php
<head>
<title></title>
<link href="css/style.css" rel="stylesheet" type="text/css">
<style type="text/css">
<!--
.style4 {
font-size: 16px;
font-weight: bold;
}
.style5 {
font-size: 12px
}
.a {
color:#000000;
text-decoration:none;
}
-->
</style>
</head>
<body>
<div style="margin-left:10px;">U Drive.lk</div>
<div class="style5" style="text-align:right; padding:10px;">
Contact Us | Disclaimer | Site Map</div>
</div>
<div>
<div style="background-image:url(images/Car3.png); border:#FFFFFF; border-style:solid; border-width:2px; border-top:none; border-bottom:none; width:920px; height:450px; margin-left:auto; margin-right:auto;" align="center">
<br/>
<img src="images/Car6.png" width="920px" height="135px" />
<div style="margin-top:-22px; height:22px; margin-left:55px;" align="left"><a class="a">Home</a></div>
<div style="margin-top:-22px; height:22px; margin-left:200px;" align="left"><a class="a">Gallery</a></div>
<div style="margin-top:-22px; height:22px; margin-left:350px;" align="left"><a class="a">Leasing</a></div>
<div style="margin-top:-22px; height:22px; margin-left:490px;" align="left"><a class="a">Testimonial</a></div>
<div style="margin-top:-22px; height:22px; margin-left:640px;" align="left"><a class="a">Forum</a></div>
<div style="margin-top:-22px; height:22px; margin-left:790px;" align="left"><a class="a">FAQ</a></div>
<div style="margin-left:auto; margin-right:auto; margin-top:20px;" >
<script type="text/javascript">
AC_FL_RunContent( 'codebase','http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0','width','920','height','135','src','Flash/Flash Header2','quality','high','pluginspage','http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash','movie','Flash/Flash Header2' ); //end AC code
</script><noscript><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=9,0,28,0" width="920" height="135">
<param name="movie" value="Flash/Flash Header2.swf" />
<param name="quality" value="high" />
<embed src="Flash/Flash Header2.swf" quality="high" pluginspage="http://www.adobe.com/shockwave/download/download.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="920" height="135"></embed>
</object></noscript>
</div>
<div align="left">
<table width="100%" border="0" style="margin-top:10px;">
<tr>
<td width="20%" valign="top" ><div align="left"><img src="images/Buy_men.png" /> <img src="images/Sell_men.png" /> <img src="images/Rent_men.png" /></div>
<div style="color:#FFFFFF;margin-top:-90px; width:38px; margin-left:10px;">Buy</div>
<div style="color:#FFFFFF;margin-top:-18px; width:38px; margin-left:65px;">Sell</div>
<div style="color:#FFFFFF;margin-top:-20px; width:38px; margin-left:115px;"><a style="color:#FFFFFF;">Rent</a></div></td>
<td width="38%"><fieldset style="background-color:#cccccc">
<span class="style4">Quick Search</span>
</fieldset></td>
<td width="42%"><fieldset style="background-color:#cccccc">
<span class="style4">Login</span>
<?php include_once('login.php'); ?>
</fieldset></td>
</tr>
</table>
</div>
</div>
</div>
<div style="margin-left:auto; margin-right:auto; width:920px;">
login.php
<?php
if (logged_in()) {
echo '<br/> View User Profile <br/>Log Out';
} else {
?>
<form action="" method="post">
<table width="100%" border="0" style="margin-top:-5px;" >
<tr>
<td><div align="left">User Name :</div></td>
<td><input type="text" name="Quick_Name" size="25" /></td>
</tr>
<tr>
<td><div align="left">Password :</div></td>
<td> <input type="text" name="PassWord" size="25" /> <input type="submit" value="Submit" /></td>
</tr>
</table>
</form>
Forgot your password / Register User
<?php
}
if (isset($_POST['Quick_Name'], $_POST['PassWord'])) {
$forgotEmail = $_POST['Quick_Name'];
$login_password = $_POST['PassWord'];
if (empty($forgotEmail) || empty($login_password)) {
$errors[] = 'Email and Password required';
} else {
$login = login($forgotEmail, $login_password);
if ($login === false) {
$errors[] = 'Unable to Log you in';
}
}
if (!empty($errors)) {
foreach ($errors as $error) {
echo $error, '<br/>';
}
} else {
$_SESSION['user_id'] = $login;
header('Location:index.php');
exit();
}
}
?>
index.php
<?php include 'init.php'; include 'widgets/header1.php'; ?>
<div>
</div>
</div>
</body>
</html>
Please Can any one help me out to solve this problem or give me a clue what I am doing here?
Thanks in Advance
In PHP, headers get sent as soon as the page starts to print something - which can occur unintentionally due to whitespace.
Based on your error message (output started at /home/multisl/public_html/udrivetest/index.php:2)
I am guessing this line of index.php:
<?php include 'init.php'; include 'widgets/header1.php'; ?>
appears on line 2 of the file? But you cannot have a line of whitespace above it, it needs to be line 1 since one of the includes is dealing with headers (cookie for session).
Otherwise the blank line 1 is "printing something" - a new line - which sends headers probably before you are intending.
Basically, check all files for not having blank lines above opening tags <?php and don't have blank lines below closing tags ?>.
This is most likely that there exists some whitespace that is sent before the session_start command, try removing the closing PHP tag (?>) and report back the results.
By doing this you remove the possibility of it outputting any invalid whitespace.
There should have some blank space sending back to client. It is a good practise to leave php closing tag ?> if your last line of code is a php code.
Make sure that you dont leave any blank space before and after the php opening tag and php closing tag
You can prevent any output to send to client by using object buffering with ob_start() .
put the ob_start at the very beginning of your php code can save you time.
I would like to consider removing ob_start() from init.php to index.php.
thanks

delete selected images with the help of checkboxes

This is a page where users can edit their uploaded images. There is a checkbox near each image. I want to delete the selected images after user clicks the "delete selected images" button (each checkbox contains the image name as value). How can I do that?
<?php
session_start();
//////////////if user already logged in go to login.php/////////
if (isset($_SESSION['email'] )&& isset($_SESSION['password'] ))
{
} else{header( "Location: login.php" ); }
include('includes/config.php');
if (isset($_POST['esubmit']) ){
$checkbox=$_POST['delete'];
echo $checkbox;
}//main one
if (isset($_POST['esubmit']) ){
} else { $clickeditid=$_GET["id"];
$_SESSION['eid']= $clickeditid ;
}
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<link href="css/css.css" rel="stylesheet" type="text/css" />
<style rel="stylesheet" type="text/css">
input {
border-style: solid;
border-color: #000000;
border-width: 1px;
background-color: #ffffff;
}
</style>
<script src="js/css_browser_selector.js" type="text/javascript"></script>
</head>
<body>
<?php
include('includes/topmenu.php');//top menu
echo '<br />';
include('includes/usermenu.php');///bcoz of this menu error occurs
////////////////////
include('includes/edit_img_menu.php');
?>
<form id="form1" name="form1" method="post" action="editimg.php?id=<?php echo $_SESSION['eid'];?>">
<table align="center" width="70%" cellspacing="0">
<tr>
<td colspan="3" align="center" bgcolor="#FFFFFF"></td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="#FFFFFF"><?php
$imgcheck=mysql_query("
SELECT *
FROM `images`
WHERE `deal_id` =$_SESSION[eid]
LIMIT 0 , 30
");
$numimgcheck=mysql_num_rows($imgcheck);
if($numimgcheck==0){echo '<span style=color:#ff0000; >No pictures uploaded</span>';}
while ($rowimg2= mysql_fetch_array($imgcheck)){
$imgname=$rowimg2['name'];
{
echo ' <a href="users/'.$_SESSION['userid'].'/images/'.$imgname.'" rel="lightbox[slide]" caption=".">';
}
{ echo '<img src="users/'.$_SESSION['userid'].'/images/thumbs/'.$imgname.'" border="0" />';}
{ echo '</a><input type="checkbox" name="delete" id="delete" value="'.$imgname.'">
';}
}
?></td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="#FFFFFF"> </td>
</tr>
<tr>
<td colspan="3" align="center" bgcolor="#95F8FD"><input name="esubmit" type="submit" class="red" id="esubmit" value="Delete selected images" /></td>
</tr>
<tr>
<td width="89"> </td>
<td colspan="2"> </td>
</tr>
</table>
</form>
</body>
</html>
You have to create a form to submit the data of the checked checkboxes and treate the submited result with the php code : if you want to put the php code on the same page, you can check if there is any data in the POST vars and create a SQL Query to delete the corresponding pictures.
You can find a very well documented tutorial here : http://sharemyphp.wordpress.com/2009/12/21/ajax-jquery-php-multiple-delete-item-with-check-box/
Regards,
Max
I use the below code to delete images in my admin panel. I saved the file as deletephoto.php. Note that this script works without login. You need to make some changes to fit your use case
<form method="post" action="deletepho.php">
<center>
<input type="submit" value="Delete" name="Delete">
</center>
<?php
\\lets assign the folder name in $title
\\You can assign any name
$title= "test";
\*$directory corresponds to whole path. Edit to your preference. (i assume u store your
images in directory named "images") */
$directory = "$title/images";
\\The array specifies the format of the files
$allowed_types=array('jpg','jpeg','gif','png');
$file_parts=array();
$ext='';
$title='';
$i=0;
$dir_handle = #opendir($directory) or die("There is an error with your image directory!");
while ($file = readdir($dir_handle))
{
if($file=='.' || $file == '..') continue;
$file_parts = explode('.',$file);
$ext = strtolower(array_pop($file_parts));
$title = implode('.',$file_parts);
$title = htmlspecialchars($title);
$nomargin='';
if(in_array($ext,$allowed_types))
{
if(($i+1)%4==0)
$nomargin='nomargin';
echo'
<div id="picture">
<img src="'.$directory.'/'.$file.'" width="150" height="150"><br>
Select <input type="checkbox" value="'.$directory.'/'.$file.'" name="imgfile[]">
\* I specified input name as an array . So that we can store in an array and delete it.*/
</div>';
}
$i++;
}
closedir($dir_handle);
\\Now we have the list of images within form elements
?>
</form>
Now here is the actual code to delete the photos. I saved it as deletepho.php.
$file = $_REQUEST['imgfile'];
$num_files=count($file);
for($i=0;$i<$num_files;$i++)
{
unlink ("$file[$i]");
}
echo "Images successfully deleted.Go <a href='deletephoto.php'>back</a>";

Categories