How to add progressbar to downloading file? [duplicate] - php

This question already has an answer here:
Show a progress bar for downloading files using XHR2/AJAX
(1 answer)
Closed 3 years ago.
I need help about this code. So I've wrote this code and now I need add progressbar and show downloaded file link after downloaded file to server...
And how I can add it to this code?
Thanks!
<html>
<p style="width: 70%;margin: auto;margin-top: 5%;font-size:larger;text-align:center">
Download Any Files From Any URL</p>
<form method="post" style="width: 70%;margin: auto;margin-top: 10%;">
<input name="url" size="50" placeholder="Please Enter Valid URL>>>" style="width: 100%;height: 10%;font-size: 1.5em;padding:10px" required>
<input name="submit" type="submit" value="Start Download" style="width: 30%;height: 10%;margin: 5% auto; display: block;">
<p style="width: 70%;margin: auto;margin-top: 10%;font-size:larger;text-align:center">
Your File Downloaded To <?php echo getcwd(); ?> Server</p>
<p style="width: 70%;margin: auto;font-size: smaller;text-align: center;position: fixed;bottom: 0;background: #fff;">
Powered by: Developers</p>
</form>
<?php
// maximum execution time in seconds
// set_time_limit (24 * 60 * 60);
if (!isset($_POST['submit'])) die();
// folder to save downloaded files to. must end with slash
$destination_folder = '';
$url = $_POST['url'];
$newfname = $destination_folder . basename($url);
/* // old script
$file = fopen ($url, "rb");
if ($file) { $newf = fopen ($newfname, "wb");
if ($newf)
while(!feof($file)) { fwrite($newf, fread($file, 1024 * 8 ), 1024 * 8 ); }
}
if ($file) { fclose($file); }
if ($newf) { fclose($newf); }
*/
file_put_contents( $newfname, fopen($url, 'r'));
?>
</html>
I need add progress bar and show link after files completed.

w3 schools has a great example of a progress bar using bootstrap:
try this code in your browser.
<!DOCTYPE html>
<html lang="en">
<head>
<title>Bootstrap Example</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
</head>
<body>
<div class="container">
<h2>Animated Progress Bar</h2>
<p>The .active class animates the progress bar:</p>
<div class="progress">
<div class="progress-bar progress-bar-striped active" role="progressbar" aria-valuenow="40" aria-valuemin="0" aria-valuemax="100" style="width:40%">
40%
</div>
</div>
</div>
</body>
</html>
the idea is that you change the aria-valuenow value as the download progresses. This would be done by using information from php about the percentage of the file that has been downloaded, and modifying that aria-valuenow to reflect the progress.

Related

website layout changes if someone adds /randomcharacters after the given url

So im quiet new to coding in general and i started making a shop page where everything is dynamiclly put throught databases . Now the thing is that for example i have created index.php file where user would directly go to and from there he can choose his next category or whatever hes looking for.
Now the issue is that if someone does like index.php/asfjasflk , the index page will render and there's missing photos / links and so on , so the thing is how to prevent that from happening even if they input something to re direct them to main website or where they are.
To show you more what im talking about.
Index normally index when someone puts something
I have a free host because i wanted to test the .htaccess file as ive seen around but it seems not working , yes i have set Rewrite to on , i set 404 page custom but it still recognizes the default one or doesnt recognize it at all .
http://agcomputers.onlinewebshop.net/index.php - this is the main file and if you do http://agcomputers.onlinewebshop.net/index.php/asfkjasfklajsfas - You still get the main file but its empty and the url is re writen if i click on other links.
Here's the loginPage code.
Note: This happens with all the pages / files in my folder/website.
require_once("../includes/db.php");
require_once("../includes/sessions.php");
require_once("../includes/functions.php");
?>
<?php
if(isset($_SESSION['User_ID']))
{
Redirect_to("dashboard.php");
}
if(isset($_POST['submit']))
{
$adminUser = $_POST['username'];
$adminPassword = $_POST['password'];
if(empty($adminUser) || empty($adminPassword))
{
$_SESSION['ErrorMessage'] = "Emri ose Passwordi eshte bosh";
Redirect_to("login.php");
}
else
{
if(CheckUsernameExistsOrNot($adminUser) == true)
{
$found_account = LoginAttempt($adminUser, $adminPassword);
if($found_account)
{
if(password_verify($adminPassword, $found_account['password']))
{
$_SESSION['User_ID'] = $found_account['id'];
$adminUser = $_SESSION['adminName'] = $found_account['adminName'];
$_SESSION['SuccessMessage'] = "Welcome $adminUser";
if(isset($_SESSION['TrackingURL']))
{
Redirect_to($_SESSION['TrackingURL']);
}
else
{
Redirect_to("dashboard.php");
}
}
else
{
$_SESSION['ErrorMessage'] = "Passwordi nuk eshte i sakt";
Redirect_to("login.php");
}
}
else
{
$_SESSION['ErrorMessage'] = "Username ose Passwordi eshte gabim";
Redirect_to("login.php");
}
}
else
{
$_SESSION['ErrorMessage'] = "Username nuk ekziston ne databaze";
Redirect_to("login.php");
}
}
}
?>`
`
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="../css/styles.css">
<script src="https://kit.fontawesome.com/496fd68b03.js" crossorigin="anonymous"></script>
<title>AG Computers</title>
</head>
<body>
<!-- SideBar Start -->
<div class="main-container d-flex">
<div class="content">
<!-- Dashboard Content -->
<div class="dashboard-content px-3 pt-4">
<div class="container container-fluid">
<div class="row ">
<div class="offset-1 col-lg-8 " >
<div class="card login-form mt-2 mb-2 p-4" style="top: 90%; ">
<?php
echo ErrorMessage();
echo SuccessMessage();
?>
<form action="login.php" method="post">
<div class="card-header">
<h3 class="text-white">Login</h3>
</div>
<label class="text-white" for="username">Username:</label>
<input type="text" id="username" name="username" class="form-control">
<label for="password" class="text-white mt-2">Password:</label>
<input type="password" id="password" name="password" class="form-control ">
<button class="btn btn-outline-info text-black form-control mt-2" type="submit" name="submit">Login</button>
</form>
</div>
</div>
</div>
</div>
</div>
</div><!-- Content Div -->
</div> <!-- Main Flex Container Div -->
<!-- FOOTER -->
<footer class="text-white" style="background-color: #000;">
<div class="container ">
<div class="row d-none d-md-block">
<p class="lead text-center">Theme by <span id="year"></span></span> © --- All Rights Reserved</p>
</div>
</div>
</footer>
<!-- End FOOTER -->
<!-- Dashboard Content End -->
<!-- SideBar End -->`
`<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.0/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/js/bootstrap.bundle.min.js"></script>
<script type="text/javascript">
$('.sidebar ul li').on('click', function(){
$('.sidebar ul li.active').removeClass('active');
$(this).addClass('active');
});
$('.open-btn').on('click', function(){
$('.sidebar').addClass('active');
});
$('.close-btn').on('click', function(){
$('.sidebar').removeClass('active');
});
</script>
</body>
</html>``
I tried to put up .htaccess and that did not work aswell
You are currently calling the CSS via this code :
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link href="https://cdn.jsdelivr.net/npm/bootstrap#5.3.0-alpha1/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-GLhlTQ8iRABdZLl6O3oVMWSktQOp6b7In1Zl3/Jr59b6EGGoI1aFkw7cmDA6j6gD" crossorigin="anonymous">
<link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootstrap#5.0.2/dist/css/bootstrap.min.css">
<link rel="stylesheet" type="text/css" href="css/styles.css">
You should change the link from relative path (href="css/styles.css")
To absolute Path (href="/css/styles.css" , or something similar depending on how your folders are organised)
otherwise, when adding a slash at the end of the URL, your code will try to get the CSS from http://agcomputers.onlinewebshop.net/index.php/styles.css, when it should be http://agcomputers.onlinewebshop.net/styles.css (again, could be different depending on how you organised your folders)
hope it helps
Edit : mistyped ./ instead of / before absolute path
Second Edit : just double checked and it seems the CSS is not the only problem, you are also calling the folders "images" and "uploads" via relative paths, which should be changed as well.
example of a wrong call of the uploads folder
uploads relative path call
Simply Put this Redirect in your Page if Someone visit it with extra Params it will redirect to vase file.
$url = 'http://' . $_SERVER['SERVER_NAME'] . $_SERVER['REQUEST_URI'];
$base_url = 'http://' . $_SERVER['SERVER_NAME'].'/'.basename(__FILE__);
if($url != $base_url)
{
header("Location:$base_url");
}

Saving a generated QR code png but getting 404 Not Found error message

I am trying to generate a QR code from the value of a HTML input element:
HTML, CSS, and JS Code:
index.php
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js"></script>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<link rel="icon" href="https://codingbirdsonline.com/wp-content/uploads/2019/12/cropped-coding-birds-favicon-2-1-192x192.png" type="image/x-icon">
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/css/bootstrap.min.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.bundle.min.js" integrity="sha384-LtrjvnR4Twt/qOuYxE721u19sVFLVSA4hf/rRt6PrZTmiPltdZcI7q7PXQBYTKyf" crossorigin="anonymous"></script>
<link rel="stylesheet" href="https://use.fontawesome.com/releases/v5.8.2/css/all.css">
<script src="https://stackpath.bootstrapcdn.com/bootstrap/4.5.2/js/bootstrap.min.js" integrity="sha384-B4gt1jrGC7Jh4AgTPSdUtOBvfO8shuf57BaghqFfPlYxofvL8/KUEfYiJOMMV+rV" crossorigin="anonymous"></script>
<title>Send Email Example</title>
<style>
.center-block {
display: block;
margin-left: auto;
margin-right: auto;
}
</style>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-sm-9 col-md-7 col-lg-5 mx-auto">
<div class="card card-signin my-5">
<div class="card-body">
<h5 class="card-title text-center">Generate QR Code</h5>
<form id="generateQrForm" class="form-signin">
<div class="form-label-group">
<label for="inputEmail">Text For QR <span style="color: #FF0000">*</span></label>
<input type="text" name="qrText" id="qrText" class="form-control" required placeholder="Enter something to generate QR">
</div> <br/>
<div id="generatedQr text-center">
<img src="" id="generatedQrImg" class="center-block">
</div> <br/>
<button type="submit" name="generateQrBtn" id="generateQrBtn" class="btn btn-lg btn-primary btn-block text-uppercase" >Generate QR</button>
</form>
</div>
</div>
</div>
</div>
</div>
<script type="text/javascript" src="generate_qr_js.js"></script>
</script>
</body>
jQuery code:
generate_qr_js.js
$("form#generateQrForm").on("submit",function (e) {
e.preventDefault();
var qrText = $("#qrText").val();
$.post("generate_qr_script.php",{generateQr:'generateQr',qrText:qrText},function (response) {
var data = response.split('^');
var generateQrImgPath = data[1];
$("#generatedQrImg").attr("src",generateQrImgPath);
})
});
PHP Code:
generate_qr_script.php
<?php
include "library/phpqrcode/qrlib.php";
if (isset($_POST['generateQr']) == 'generateQr')
{
$qrText = $_POST['qrText']; // receive the text for QR
$directory = "generated_qr/"; // folder where to store QR
$fileName = 'QR'.rand().'.png'; // generate random name of QR image
QRcode::png($qrText, $directory.$fileName, 'L', 4, 2); // library function to generate QR
echo "success^".$directory.$fileName; // returns the qr-image path
}
?>
I run these 3 codes under one folder along with phpqrcode library that is imported in generate_qr_script.php file. When I go to the index.php website using XAMPP server, I get an error saying "404 Not Found" as shown below:
When I inspect the source code, the image source is generated successfully but it doesn't get shown on the web.
What I am trying to do is to generate a QR code that captures what the user inputs into the text box that is written in the HTML code. Ideally, it would be nice to store the barcode into the local computer file within the same folder but the code does not load the desired QR code png.
If anyone has any suggestions on where I am going wrong or has a better idea to generate a barcode please do let me know.
I think I fixed it by changing the file permission where I wanted to save the images somehow!

Storing Webcam Image

I have this code to capture an image from the webcam, and I need to store it in a directory on my laptop.
<!DOCTYPE html>
<html>
<head>
<title>Capture webcam image with php and jquery - ItSolutionStuff.com</title>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/webcamjs/1.0.25/webcam.min.js"></script>
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/twitter-bootstrap/4.1.3/css/bootstrap.min.css" />
<style type="text/css">
#results { padding:20px; border:1px solid; background:#ccc; }
</style>
</head>
<body>
<div class="container">
<h1 class="text-center">Capture webcam image with php and jquery - ItSolutionStuff.com</h1>
<form method="POST" action="storeImage.php">
<div class="row">
<div class="col-md-6">
<div id="my_camera"></div>
<br/>
<input type=button value="Take Snapshot" onClick="take_snapshot()">
<input type="hidden" name="image" class="image-tag">
</div>
<div class="col-md-6">
<div id="results">Your captured image will appear here...</div>
</div>
<div class="col-md-12 text-center">
<br/>
<button class="btn btn-success">Submit</button>
</div>
</div>
</form>
</div>
<!-- Configure a few settings and attach camera -->
<script language="JavaScript">
Webcam.set({
width: 490,
height: 390,
image_format: 'jpeg',
jpeg_quality: 90
});
Webcam.attach( '#my_camera' );
function take_snapshot() {
Webcam.snap( function(data_uri) {
$(".image-tag").val(data_uri);
document.getElementById('results').innerHTML = '<img src="'+data_uri+'"/>';
} );
}
</script>
</body>
</html>
This is the index.php file, and the next one is the php file to save image.
<?php
$img = $_POST['image'];
$folderPath = "upload/";
$image_parts = explode(";base64,", $img);
$image_type_aux = explode("image/", $image_parts[0]);
$image_type = $image_type_aux[1];
$image_base64 = base64_decode($image_parts[1]);
$fileName = uniqid() . '.png';
$file = $folderPath . $fileName;
file_put_contents($file, $image_base64);
print_r($fileName);
?>
I have also created the 'upload' folder, but the image is still not getting saved.
I've made a folder names 'webcam' on my desktop, inside that folder are these two files, and the other folder named 'upload'.
How do i get the image to save in that folder?

Image not moved from tmp dir to another folder in linux server

I have designed a web site which takes image as input and by using ajax I have displayed the image.It was working fine locally but when I uploaded it into the server the image is not shown. The process that takes place is: 1)User uploads an image 2)The image is stored in a temporary folder by default 3)The image that is stored in the temporary folder is moved to a folder upload 4) The image is displayed in a div. I checked the path but it seems okay for me. I will post the code for review:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<link rel="stylesheet" href="MainStyleSheet.css" type="text/css">
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js"></script>
<script src="html5slider.js"></script>
<script type="text/javascript" src="scripts/jquery.form.js"></script>
<script type="text/javascript">
$(document).ready(function()
{
$('#file').live('change', function()
{
$("#preview").html('');
$("#preview").html('<img src="images/loader.gif" alt="Uploading...."/>');
$("#imageform").ajaxForm(
{
target: '#preview'
}).submit();
});
</script>
<script type="text/javascript">
function myfunction()
{
$("#display").html('');
$("#display").html('<img src="images/loader.gif" alt="Uploading...."/>');
$("#retrieveimageform").ajaxForm(
{
target: '#display'
}).submit();
$("#tagsform").ajaxForm(
{
target: '#tags'
}).submit();
};
</script>
<title></title>
</head>
<body>
<div id="maindiv">
<div id="banner">
<?php
include 'Header.php';
?>
</div>
<div id="wrapper">
<div id="imageupload">
<form action="uploadimage.php" method="post"
enctype="multipart/form-data" id="imageform">
<label for="file">Upload your image:</label>
<input type="file" name="file" id="file"><br>
</form>
</div>
<div id='preview'>
</div>
<div id='tags'>
</div>
</form>
<div class="clear"></div>
........................................
<div id="footer">
<?php
include 'Footer.php';
?>
</div>
</div>
<div id='screen'>
</div>
</body>
</html>
The uploadimage.php contains:
<?php
session_start();
$allowedExts=array("gif","jpeg","jpg","png");
$extension= end(explode(".", $_FILES["file"]["name"]));
if((($_FILES["file"]["type"]=="image/gif")
||($_FILES["file"]["type"]=="image/jpeg")
||($_FILES["file"]["type"]=="image/jpg")
||($_FILES["file"]["type"]=="image/png"))
&& ($_FILES["file"]["size"]<2000000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"]>0)
{
echo "Error:".$_FILES["file"]["error"]."<br>";
}
else{
// echo "Upload: ".$_FILES["file"]["name"]."<br>";
// echo "Store in: ".$_FILES["file"]["tmp_name"]."<br>";
move_uploaded_file($_FILES["file"]["tmp_name"],"upload/".$_FILES["file"]["name"]);
//echo "Stored in "."upload/".$_FILES["file"]["name"];
echo "<img src='upload/".$_FILES["file"]["name"]."' class='preview' height='300' width='250'>";
$_SESSION['img']="upload/".$_FILES["file"]["name"];
}
}
else
{
echo "Invalid file";
}
?>
In the server the image is not stored in the upload folder when the user given an input and the image is not shown. Any solutions?:Please help. The server is linux server.
The problem is with file permission.
use the following command
sudo chmod 777 absolute_path_of_you_dir
on Ubuntu.

XML 'Select Where' Statement

I wonder whether someone may be able to help me please.
I'm using Aurigma's 'Image Uploader' software to allow users to add, and view images for the records they create with the image data collected and retrieved via an XML file.
One of the pages I've put together creates a gallery which allows the user to view the images, both individually and as part of a 'fancybox' slideshow. The script for this is shown below.
<!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">
<?php
$galleryPath = 'UploadedFiles/';
$thumbnailsPath = $galleryPath . 'Thumbnails/';
$absGalleryPath = realpath($galleryPath) . DIRECTORY_SEPARATOR;
$descriptions = new DOMDocument('1.0');
$descriptions->load($absGalleryPath . 'files.xml');
?>
<head>
<title>Gallery</title>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<link href="Libraries/fancybox/jquery.fancybox-1.3.1.css" rel="stylesheet" type="text/css" />
<link href="Styles/style.css" rel="stylesheet" type="text/css" />
<!--[if IE]>
<link href="Styles/ie.css" rel="stylesheet" type="text/css" />
<![endif]-->
<script src="Libraries/jquery/jquery-1.4.3.min.js" type="text/javascript"></script>
<script src="Libraries/fancybox/jquery.fancybox-1.3.1.pack.js" type="text/javascript"></script>
<script type="text/javascript">
$(function() { $('a.fancybox').fancybox(); });
</script>
<style type="text/css">
<!--
.style1 {
font-size: 14px;
margin-right: 110px;
}
.style4 {font-size: 12px}
-->
</style>
</head>
<body style="font-family: Calibri; color: #505050; font-size: 9px; border-bottom-width: thin; margin-top: 5px; margin-left: -475px; margin-right: 1px; margin-bottom: -10px;">
<div align="right" class="style1"> <a href = "imagefolders.php" /> View Uploaded Images In Folder Structure <a/> ← View All Uploaded Images </div>
<form id="gallery" class="page">
<div id="container">
<div id="center">
<div class="aB">
<div class="aB-B">
<?php if ('Uploaded files' != $current['title']) :?>
<?php endif;?>
<div class="demo">
<div class="inner">
<div class="container">
<div class="gallery">
<ul class="gallery-image-list">
<?php for ($i = 0; $i < $descriptions->documentElement->childNodes->length; $i++) :
$xmlFile = $descriptions->documentElement->childNodes->item($i);
$name = htmlentities($xmlFile->getAttribute('originalname'), ENT_COMPAT, 'UTF-8');
$description = htmlentities($xmlFile->getAttribute('description'), ENT_COMPAT, 'UTF-8');
$folder = htmlentities($xmlFile->getAttribute('folder'), ENT_COMPAT, 'UTF-8');
$source = $galleryPath . rawurlencode($xmlFile->getAttribute('source'));
$thumbnail = $thumbnailsPath . rawurlencode($xmlFile->getAttribute('thumbnail'));
?>
<li class="item">
<a class="fancybox" target="_blank" rel="original" href="<?php echo $source; ?>"><img class="preview"
alt="<?php echo $name; ?>" src="<?php echo $thumbnail; ?>" /></a> </li>
<li class="item"></li>
<p><span class="style4"><b>Image Description:</b> <?php echo htmlentities($xmlFile->getAttribute('description'));?> <br />
<b>Image contained in folder:</b> <?php echo htmlentities($xmlFile->getAttribute('folder'));?> </span><br />
<?php endfor; ?>
</li>
</p>
</ul>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
</div>
<div class="aB-a"> </div>
</div>
</div>
</div>
</form>
</body>
</html>
What I'd like to be able to do is now make the images that are retrieved, user specific, i.e. User A can only view their images.
If this information was being retrieved straight from a mySQL database I know that within PHP I can use the 'SELECT WHERE' statement to filter the returned records, but could someone tell me please is there an XML equivalent that I could use?
Many thanks
Allowing users to view only their own uploaded images is not such a simple task. If the images are stored in a publically accessable folder then anybody can view the images using their browser.
To achieve this there are a few alternatives such as:
storing the images in the database rather than the filesystem,
creating a new foler for each user on the filesystem and changing
the read write permissions for each folder, or
storing the images outside the web root and fetching the images
using php i.e.
Instead of providing a link to an image. Provide a link to a cgi
script which will automatically provide the proper header and
content of the image.
For example: image.php?sample.jpg
You can then make sure they are already authenticated (e.g. pass a
session id) as part of the link.
This would be part of the header, and then your image data can
follow.
<?php
$file = basename(urldecode($_GET['file']));
$fileDir = '/path/to/files/';
if (file_exists($fileDir . $file))
{
//perform some authorisation check
...
...
// Note: You should probably do some more checks
// on the filetype, size, etc.
$contents = file_get_contents($fileDir . $file);
// Note: You should probably implement some kind
// of check on filetype
header('Content-type: image/jpeg');
echo $contents;
}
?>

Categories