Save screenshot using html2canvas to web folder - php

I have a website, where user can take screenshot of that website and that screenshot should save automaticly to folder "posters" inside my "www" folder.
But when I try to make an screenshot, it is saved directly to "www" folder and not to the "posters" folder. I tried to change atributes of the "posters" folder to 777 but It did not helped. And also, that "posters" folder gives this error: Forbidden You don't have permission to access /posters/ on this server. when I try to visit it via browser. I dont know what is wrong.
Here is my save.php code:
<?php
//Get the base-64 string from data
$filteredData = substr($_POST['img_val'], strpos($_POST['img_val'], ",") + 1);
//Decode the string
$unencodedData = base64_decode($filteredData);
//Save the image
file_put_contents('img_' . date("U") . '.png', $unencodedData);
move_uploaded_file('img.png', './posters/$newname');
?>
<h2>Save the image and show to user</h2>
<table>
<tr>
<td>
<a href="img.png" target="blank">
Click Here to See The Image Saved to Server</a>
</td>
<td align="right">
<a href="index.php">
Click Here to Go Back</a>
</td>
</tr>
<tr>
<td colspan="2">
<br />
<br />
<span>
Here is Client-sided image:
</span>
<br />
<?php
//Show the image
echo '<img src="' . $_POST['img_val'] . '" />';
?>
</td>
</tr>
</table>
<style type="text/css">
body, a, span {
font-family: Tahoma; font-size: 10pt; font-weight: bold;
}
</style>
Is it possible to make something like this? file_put_contents(.PathToFolder/'img_' . date("U") . '.png', $unencodedData);

Related

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

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

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.

Error State 301 Uploading Images in WordPress

I'm working on a project that is to take a standalone PHP application and move it to WordPress. I've done that and now within WordPress, I am working a particular registration sequence for soccer players to register themselves as players for a team. At a point in the sequence the user uploads an image of themselves. In the code, it is the file 'select-image.php' that is then attempting to retrieve 'upload-image.php' and edit-image.php' but returning error codes 301 an 302 respectively for each.
I've attached a screenshot showing the network activity when upload-image.php and edit-image.php are attempted to be retrieved. Neither resource has been moved permanently. I've also attached a screenhot showing the file is in fact where it is supposed to be on the server.
'select-image.php'
<?php
require_once $_SERVER ['DOCUMENT_ROOT'] . '/required-php-db-connect.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/session-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/ACS-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/org-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/constants-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/cart-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/division-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/team-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/user-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/form-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/image-library.php';
// request page post variables here, ensure that '/libraries/form-library.php' is required above
$return_page = "";
if(!empty($_POST["return_page"])){
$return_page = $_POST["return_page"];
}
// pre-header php functions (such as ACS activities)
$return_page = "";
if(!empty($_POST["return_page"])){
$return_page = $_POST["return_page"];
}
$image_mode = get_session_value('image_mode');
if ($image_mode == "") {
$image_mode = optional_form_item('image_mode');
}
if ($image_mode == 'cart_image_mode'){
$debug_mode = get_session_value('debug_mode');
$debug_string = "";
$transaction_id = get_session_value('transaction_id');
$user_cart = new Cart();
$user_cart->load_cart($transaction_id);
$cart_user_info = new cart_user_info();
$cart_user_info->load_cart_user_info_by_transaction_id($transaction_id);
$user_id = $cart_user_info->get_cart_user_info_user_id();
} else {
$user_id = optional_form_item('user_id');
$team_id = optional_form_item('team_id');
set_session_value('edit_team_id',$team_id);
}
set_session_value('image_edit_user_id', $user_id);
// load jquery libraries
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/jquery-link-library.php';
// load common css libraries
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/css-link-library.php';
$age_level = get_session_value('age_level');
if($age_level == 'youth') {
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/bootstrap-library.php';
}
//get default season
$this_season = new Season();
$season_text = $this_season->display_current_soccer_year();
$error_message = get_session_value('error_message');
set_session_value('error_message', null);
// load page specific css libraries
//require once $_SERVER['document_root'].'/libraries/roster.css';
?>
<!-- all local style references go here. USE SPARINGLY! -->
<style type=text/css>
.inactive_step {
font-weight: normal;
border:thin #000000 solid;
display:inline-block;
}
.active_step {
font-weight: bold;
border: thin #FF0000 solid;
display:inline-block;
}
</style>
</head>
<body id='body'>
<div class="wrapper">
<!-- location of libraries that display data to the page, in the order that the data is displayed -->
<?php if($age_level == 'youth') { require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/new-menu-bar.php'; } else { require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/menu-bar.php'; } ?>
<?php require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/admin-header.php'; ?>
<div class="main_body">
<!-- place all content here -->
<?php
if($age_level == 'youth'){
echo '<div class="jumbotron" style="margin: auto;">';
}
//$image_path = determine_user_image_path($user_id) . "/". get_user_image_file_name($user_id);
$image_path = get_image_database_path_and_name($user_id);
//1:
//place ACS and id user info here
//$user_id = get_cart_session_id();
if (empty($error_text)){
//create page output here
} else {
$display_data = $error_text;
}
?>
<font style="font-size: 18pt; color: red; align: center;"><?php echo $error_message; ?></font>
<table align="center" cellspacing="0" cellpadding ="0" width="1000" style="border: solid black 2px; align-self: center; margin: auto;">
<?php
if ($image_mode == 'cart_image_mode' && $age_level != 'youth'){
echo '<tr style = "border-bottom: solid black 2px;">';
echo '<td colspan="2" width="1000" align="center">';
display_progress(3);
echo "</td> </tr>";
} else if($image_mode == 'cart_image_mode' && $age_level == 'youth') {
echo '<tr>
<td colspan=2>
<h1>Youth Player Registration</h1>
<h3>' . trim($season_text) . '</h3>
</td>
</tr>
<tr>
<td colspan="2" width="970" align="center">';
display_new_progress(5);
echo "</td> </tr>";
}
?>
<tr>
<td valign="top" colspan =2 align= 'center' style = "font-size: 18px;"> <!-- BOTH sides of box -->
<table cellspacing=0 cellpadding=3 border=0 width=1000 align='center' >
<tr>
<td colspan="2" align="left" style="padding-left: 10px;">
<br />
Click <strong>Browse</strong> to upload your picture or take a picture with your cell phone.
<br />
<br />
Please select a picture that clearly shows your face.
<br /><br />
A small camera picture works MUCH better than a facebook picture. You will have a chance to rotate and crop the picture to select just your face. If you cannot get a picture to load correctly, it is probably too large in size or dimension. Use a smaller picture.
<br /> <br />
You MUST click on the box, shown below on the left (Current Picture), at least once for your picture to show up correctly.<br /><br /> Once you find the file or select your picture, click <strong>Upload Picture</strong>.
<br />
<br />
</td>
</tr>
<tr >
<td align="center">
<font style="font-size:16px;">Current Picture</font>
<br>
<img src="<?php echo $image_path; ?>" height="200px;" width="200px;"><br />
<br />
</td>
<td align="center" >
<br />
<form enctype="multipart/form-data" method="post" id="select_image_form" action="/images/upload-image.php" style='font-size: 18px;'>
<div class="row">
<label for="fileToUpload" style='font-size: 18px;'></label>
<button style='height: 70px; width: 250px; font-size:18px;' onclick="document.getElementById('fileToUpload').click();">Click here to select a file or take a pic with your phone</button>
<div style='height: 0px;width: 0px; overflow:hidden;'>
<input type="file" accept="capture=camera" name="fileToUpload" id="fileToUpload" style='font-size: 18px;' onchange="var x = document.getElementById('fileToUpload').value;document.getElementById('file_display').value = x; "/>
</div><br />
File to upload: <input type=text id="file_display" ></input>
<input type="hidden" name = "user_id" value = "<?php echo $user_id ?>">
<input type="hidden" name = "return_page" value = "<?php echo $return_page ?>">
</div>
<div class="row">
<br />
<input type="submit" style='font-size: 18px;' value="Upload This Picture" />
</div>
</form>
<br>
<form action="/images/edit-image-action.php" method="post">
<input type = 'hidden' name = 'image_action' value = 'save_old' />
<input type='hidden' name='old_path' value = '<?php echo $image_path; ?>' />
<input type="submit" style='font-size: 18px;' value="Keep the Current Pic and Skip This Step">
</form>
</td>
</tr>
</table><br />
<!-- Add in javascript based 'press button once' feature -->
</td>
</tr>
</table>
</div> <!-- end of main content area -->
<?php require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/user-footer.php'; ?>
</div> <!-- end of wrapper -->
</body>
</html>
<script type="text/javascript">
$( "#select_image_form" ).validate({
rules: {
fileToUpload: {
required: true,
accept: "image/*"
}
},
messages: {
fileToUpload:{
required: "You must select a picture to continue",
accept: "You must select an Image File."
}
}
});
</script>
'upload-image.php'
<?php
require_once $_SERVER ['DOCUMENT_ROOT'] . '/required-php-db-connect.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/session-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/ACS-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/user-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/cart-library.php';
require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/image-library.php';
$debug_mode = get_session_value('debug_mode');
$debug_string = "";
$debug_string .= "<br/> Debug Mode: $debug_mode";
$redirect_url = "/images/edit-image.php";
//set memory limit to accomodate uploading of 8MB images -TF
ini_set("memory_limit", "512M");
//$user_id = get_cart_session_id();
$image_mode = get_session_value('image_mode');
if ($image_mode == 'admin_image_mode'){
$user_id = get_session_value('image_edit_user_id');
}else {
$transaction_id = get_session_value('transaction_id');
$cart_user_info = new Cart_user_info();
$cart_user_info->load_cart_user_info_by_transaction_id($transaction_id);
$user_id = $cart_user_info->get_cart_user_info_user_id();
}
if ($_FILES['fileToUpload']['error'] > 0) {
$debug_string .= UploadException($_FILES['fileToUpload']['error']);
} else {
// array of valid extensions
$validExtensions = array('.jpg', '.jpeg', '.gif', '.png');
// get extension of the uploaded file
$fileExtension = strtolower(strrchr($_FILES['fileToUpload']['name'], "."));
// check if file Extension is on the list of allowed ones
if (in_array($fileExtension, $validExtensions)) {
// we are renaming the file so we can upload files with the same name
// we simply put current timestamp in front of the file name
$newName = time() . '_' . $_FILES['fileToUpload']['name'];
$destination = '/images/temp/' . $newName;
if (move_uploaded_file($_FILES['fileToUpload']['tmp_name'], 'c:/inetpub/wwwroot'.$destination)) {
$manipulator = new ImageManipulator();
$manipulator->setImageFile($_SERVER[ 'DOCUMENT_ROOT' ] . $destination);
$manipulator->rotate('360');
// rotate 360 degrees
//$newImage = rotateImage($image, 360);
//$manipulator->setImageResource($newImage);
$manipulator->save($_SERVER[ 'DOCUMENT_ROOT' ] . $destination);
//redirect_post($redirect_url, 'destination', $destination);
set_session_value("destination",$destination);
//header('Location: ' . $redirect_url);
}
} else {
$debug_string .= " <br/>You must upload an image...<br/> If the file you attempted to upload was an image, it may not be compatible with this system. Please try again with another file.";
}
}
?>
<html>
<head>
<title>save a picture</title>
<!-- all stylesheets go here -->
<link rel="stylesheet" href="/CSS/login.css" type="text/css" />
<link rel="stylesheet" href="/CSS/menu.css" type="text/css" />
<link rel="stylesheet" href="/CSS/common.css" type="text/css" />
<link rel="stylesheet" href="/images/demos.css" type="text/css" />
<link rel="stylesheet" href="/images/jquery.Jcrop.css" type="text/css" />
</head>
<body style="text-align:center;">
<div class="wrapper">
<!-- location of libraries that display data to the page, in the order that the data is displayed -->
<?php require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/logo-header.php'; ?>
<?php require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/menu-bar.php'; ?>
<?php require_once $_SERVER ['DOCUMENT_ROOT'] . '/libraries/admin-header.php'; ?>
<div class="main_body">
<!-- place all content here -->
<?php
$next_page = $redirect_url;
$debug_string .= "<br/> Next page: $next_page";
$debug_string .= "<br/> Debug Mode: $debug_mode";
echo $debug_string;
upload_image_button($user_id);
header("location: $next_page");
continue_or_debug($next_page, $debug_mode);
?>
</div>
</div>
</body>
</html>
If you need 'edit-image.php' I can post that.
I don't understand why the error is saying the resource 'upload-image.php' has been permenently moved when it is very clearly sitting in the directory it needs to be in?
What gives?
Thanks,
CM
Network activity screenshot
screenshot of resource on server

Retrieving images from the path data saved at SQL database

Part of my code to retrieve the stores images and the content from the SQL database (only the path is saved at the database) is as follows. I get the content displayed except the images.
My database record says the path as; C:/xampp/htdocs/bro/productLoader/uploaded_files/1377935517-IMG_0150.JPG
The image source I entered does not seems to be helping me. How do I adjust my approach to make sure the pictures are extracted from the database?
code as follows;
<?php
$j=0;
while ($rows = mysql_fetch_assoc($query))
{
?>
<tr style="height:100px; font-family: Georgia, 'Times New Roman', Times, serif;">
<td style=" width:100px;">
<img src='<?php $rows['pictures'];?>'><br><br>
</td>
<td style="text-align:justify;"><?php echo $rows['description'];?><br><br></td>
<td style="text-align:right;"><?php echo $rows['brand'];?><br><br></td>
<td style="text-align:right;"><?php echo $rows['model'];?><br><br></td>
<td style="text-align:right;"><?php echo $rows['unitprice'];?><br><br></td>
<td style="text-align:right;"><?php echo $rows['availability'];?> units available<br><br></td>
<td><input type='submit' id='buynow[]' class='buynow' name='but' value='Buy'><br><br></td>
</tr>
<?php
$j++;
}
echo "</table>";
}?>
You have to insert only relative path excluding your document root. That is if your document root is set till htdocs folder only (which is default in apache for localhost) then you have to insert image path from this document root in your case
/bro/productLoader/uploaded_files/1377935517-IMG_0150.JPG
And yes you need to echo that variable too.
Try html link first
<img src='bro/productLoader/uploaded_files/1377935517-IMG_0150.JPG' />
Ok
Try this fixed:<img src='<?php echo substr_replace($rows['pictures'], '',0, 16);?>'/>

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