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 - <?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>
And this one to display the images - <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>
Any help would be great
Thanks
2 2662 Atli 5,058
Recognized Expert Expert
Hey.
There are a few problems there you need to look into. - Line #27. You use a variable $file, which I don't see you create anywhere. What is that supposed to be?
- You say you get a "headers already sent" error. What is printed before that error? - There must be something, or you would not be getting the error. - It's best to post all the errors, and whole error messages, not just the highlights. (All that info is printed for a reason :])
- Your show_image.php code is trailed by HTML tags, which it should not. - The file represents and image, and adding HTML tags to the end of an image may corrupt it, causing browsers not to display it properly.
Hi thanks for the help! I solved the problem
Sign in to post your reply or Sign up for a free account.
Similar topics |
by: Bob Bedford |
last post by:
I've a page where the user may enter some values and upload some pictures.
Unfortunately, some pictures coming from digital camera are very big, and
take a lot of time for uploading.
I've...
|
by: Dave Smithz |
last post by:
Hi There,
I have a PHP script that sends an email with attachment and works great when
provided the path to the file to send.
However this file needs to be on the same server as the script.
...
|
by: 8anos |
last post by:
Hello,
I am new at the community and newbie at programming :)
As you may know rapidshare provides a perl script for linux, to upload files at their servers.
You can find the original scripts at...
|
by: Event Horizon |
last post by:
Hi,
I'm trying to add an simple upload applet to shopping cart script. My new
applet form sends all needed post fields ( quantity, product, etc... )
but the "file" post field is hardcoded in...
|
by: KevinADC |
last post by:
Note: You may skip to the end of the article if all you want is the perl code.
Introduction
Uploading files from a local computer to a remote web server has many useful purposes, the most...
| |
by: camphor |
last post by:
hi,
I have found an upload script in hotscripts and have implemented it into the website, I followed the installation steps to 'give write permissions to php on the upload folder (which is...
|
by: petershaman |
last post by:
Hi
I have a gorgeous flash image gallery, it would work perfectly fine but there's a small problem I can't upload anything thru it's upload script, since I'm getting an error 403. It's so because...
|
by: MoroccoIT |
last post by:
Greetings -
I saw somewhat similar code (pls see link below) that does mupltiple files upload. It works fine, but I wanted to populate the database with the same files that are uploaded to...
|
by: chennaibala |
last post by:
can any one send me mutiple image upload program and save the file name with extension in mysql table.we must cheak uploaded file type like bmp or any image file while uploading.
i develop...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
| |
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
|
by: conductexam |
last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
|
by: adsilva |
last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
| |
by: 6302768590 |
last post by:
Hai team
i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
| |