Hi everybody.
Im currently developing an application where users can upload files and later get acess to the url.
Im now having this trouble with header Cannot modify header information – headers already sent
This is my code so far
And this one to display the images
Any help would be great
Thanks
Im currently developing an application where users can upload files and later get acess to the url.
Im now having this trouble with header Cannot modify header information – headers already sent
This is my code so far
Code:
<?php #script 10.52 - show_image.php
$name = FALSE;//flag variable:
//check for an image in the URL:
if (isset($_GET['image'])){
//Full image path:
$image = "c://xampp/uploads/{$_GET['image']}";
//check that the image exists and is a a file:
if(file_exists ($image)&& (is_file($image))){
//make sure it has and image extension
$ext = strtolower (substr ($_GET['image'], -4));
if (($ext=='.jpg')OR ($ext=='jpeg')OR( $ext== 'gif') OR ($ext=='pdf') OR ($ext == 'txt')) {
//Set the name as this image:
$name = $_GET['image'];
}//End of $ext IF.
}//End of file_exists() IF.
}//end of isset ($_GET['image'])IF.
//if there was a problem, use the default image:
if (!$name){
$image = 'images/unvaliable.png';
$name = 'unvailable.png';}
//Get the image information:
$info = getimagesize($image);
$fs = filesize($image);
//send the content information:
header("Content-Type: " . $file['mime_type']);
print($image.$file['name']);
//Send the file:
//readfile ($image);
?>
</body>
</html>
Code:
<script language="javascript">
<!--//hide from old browsers.
//Make a pop up window function:
function create_window (image, width, height){
//add some pixels to the width and height:
width = width + 10;
height = height + 10;
//if the window is already open,
//resize it to the new dimensions;
if (window.popup && !window.popup.closed) {
window.popup.resizeTo(widht, height);
}//Set the window properties
var specs = "location=no,
scrollbars=no, menubars=no,
toolbars=no, resizable=yes, left=0, top=0, width="+ width +", height="+ height;
//Set the URL:
var url = "show_image.php?image="+ image;
//create the popup window:
popup = window.open(url,"imagewindow", specs);
popup.focus();
}//end of function
//--></script>
</head>
<body>
<p>click on and image to view it in a separate window.</p>
<table align="center"
cellpadding="5" cellspacing="5" border="1">
<tr>
<td align="center"><b>image name</b></td>
<td align="center"><b>image size</b></td>
</tr>
<?php #script 10.4 - images.php
// this script lists the images in the upload directory
$dir = 'c://xampp/uploads';//define the directory to view
$files = scandir($dir);//Read all the images into an array.
//display each image caption as a link to the javascript function:
foreach ($files as $image){
if(substr($image,0 ,1)!='.'){//ignore anything starting with a period
//get the image's size in pixels
$image_size = getimagesize("$dir/$image");
//calculate the image's size in kilobytes:
$file_size = round (( filesize ("$dir/$image"))/1024). "kb";
//make the image's name url -safe:
$image= urlencode($image);
//print the information:
echo "\t<tr>\t\t<td><a href=\"show_image.php?image=$image\">$image</a></td>\t\t<td>$file_size</td>\t</tr>\n";
}//End of the IF.
}//End of foreach loop
?>
</table>
</body>
</html>
Thanks
Comment