473,466 Members | 1,360 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Download Header Error Trapping

ak1dnar
1,584 Recognized Expert Top Contributor
Hi,
I am creating script to download some files using download dialog box.First time i tried to use ajax for this, but i failed.
So i went through this way,

By Using this function i am going to submit the Data to process to PHP.
JS Function:
Expand|Select|Wrap|Line Numbers
  1. function file_down(fid)
  2. {
  3. window.location = "download.php?fid="+fid;
  4. }

Calling Function
[PHP]<a href="javascript:file_down('.$row['p_id'].')" ><img src="images/down.jpg" /></a>[/PHP]
download.php
[PHP] <?php
$fid = $_REQUEST['fid'];
require 'dbcon.php';
$sql="SELECT p_man FROM products where p_id = '$fid'";
$result=mysql_query($sql) or die("File Not Found : " . mysql_error());
$row = mysql_fetch_assoc($result);
$file = $row['p_man'];
$FILE_ROOT = "user_manuals/";
$path = $FILE_ROOT.$file;
if($file)
{
header("Content-Type: application/octet-stream");
header("Content-Length: " . filesize($path));
header('Content-Disposition: attachment; filename="'.$file.'"');
readfile($path);
}
else
{
/*If the file Name is Not Available in the Table,
I need to OPen another POP UP window to display the File Not Found Message.
Or Any Other way to Display the Eror.
*/
}
?>[/PHP]
When I am sending ID from JS function to PHP side it will OPEN the save as Dialog box. But if the File Name is Missing in the table ERRORS will Display under download.php. What i need actually prevent this probleme. That means i want to I am not going to redirect th user back to the Download.php page if errors found.

In that case from the first page itself i want to display a ERROR window.
JS or HTMP Pop up.
Mar 15 '07 #1
6 2294
vssp
268 Contributor
Can you send me the error so we can easily identify your problem
Mar 15 '07 #2
ak1dnar
1,584 Recognized Expert Top Contributor
Errors will Get Based on two things here.
One is in the Table Name of the File is Missing.
second In the FILE_ROOT the file is Unavailable.

I want trap those two errors. Again As i said earlier I need to display this Error Messages in this Manner.

From the First Page ID will Pass to Dpwnload.php, from there if the is No Error Save as DIalog Box will display.
If Not I need to Display the Error Like File Not Found. But User Should be there at the First page Not in the download.php page.
Or elese first page is Still in the focus and File Not Found Pop up shoul Display. Any Idea.
This Error is Getting if there is No File in The File Root DIR.

Expand|Select|Wrap|Line Numbers
  1. Warning: filesize() [function.filesize]: stat failed for user_manuals/1.pdf in D:\AppServ\www\WEB_SITE\download.php on line 13
  2.  
  3. Warning: Cannot modify header information - headers already sent by (output started at D:\AppServ\www\WEB_SITE\download.php:13) in D:\AppServ\www\Akita\akita_store\download.php on line 13
  4.  
  5. Warning: Cannot modify header information - headers already sent by (output started at D:\AppServ\www\WEB_SITE\download.php:13) in D:\AppServ\www\Akita\akita_store\download.php on line 14
  6.  
  7. Warning: readfile(user_manuals/1.pdf) [function.readfile]: failed to open stream: No such file or directory in D:\AppServ\www\WEB_SITE\download.php on line 15
  8.  
Mar 15 '07 #3
merseyside
48 New Member
Try using the file_exists() function in the conditional of your if statement rather than the string. I think an empty or non empty string is always evaluated to true.

http://uk2.php.net/manual/en/function.file-exists.php
Mar 16 '07 #4
ak1dnar
1,584 Recognized Expert Top Contributor
Try using the file_exists() function in the conditional of your if statement rather than the string. I think an empty or non empty string is always evaluated to true.

http://uk2.php.net/manual/en/function.file-exists.php
[PHP]$file = $row['p_man'];// File_name.pdf as the value to $file
$FILE_ROOT = "user_manuals/";
$path = $FILE_ROOT.$file;

if(file_exists($path))
{
//headers goes here
}[/PHP]

Because of this $FILE_ROOT this will always evaluated to true. so my Php File will download.that means when there is no value in the table also this condition will set to true.
Mar 17 '07 #5
devsusen
136 New Member
Hi,

I think its better to use is_file() instead of file_exists() as the 2nd function can evaluate true if the path for the file exists. But is_file() will evaluate only true if the file really exists in the specified path.

susen
Mar 17 '07 #6
ak1dnar
1,584 Recognized Expert Top Contributor
Hi,

I think its better to use is_file() instead of file_exists() as the 2nd function can evaluate true if the path for the file exists. But is_file() will evaluate only true if the file really exists in the specified path.

susen
Thank you very much susen its a new function for me. thanks again. :)
Mar 18 '07 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

18
by: Frank Thorstens | last post by:
Hi, i try to give my script headers so the output text would be downloaded in the client's browser and not displayed. But it doesn't work at all in my IE 6 and Opera. <?...
5
by: Brandon Walters | last post by:
I wrote a file download module for my website. The reason for the file download module is that my website downloads work on a credit based system. So I need to keep track of and limit daily...
13
by: Thelma Lubkin | last post by:
I use code extensively; I probably overuse it. But I've been using error trapping very sparingly, and now I've been trapped by that. A form that works for me on the system I'm using, apparently...
3
by: Smriti Dev | last post by:
Hi There, I have the following code and when I try to run it, I get a type mismatch error. I would really appreciate your help with this. Thanks kindly, smriti --- Private Sub cmdOK_Click()
2
by: Captain Nemo | last post by:
I'm still using Office 2000 myself, but some of my clients have Office 2003. I've recently added a piece of code to create an instance of Word, open a document, fill in the blanks and become...
0
by: jinnareddy | last post by:
Hi, I'm unable to download a file that is having a 2-byte char in its name (e.g.テ) using force download option. Though, am able to download file names involving ASCII chars. I have tried URL...
14
by: Irfan12 | last post by:
i dont know php & i want a script that when a user click on a mp3 hyperlink, the mp3 file start downloading instead of start playing in media player. i got a sxript from internet search. i am using...
7
by: lawrence k | last post by:
I've got a music studio for a client. Their whole studio is run with Macintosh computers. Macintosh computers allow file names to have open white spaces, such as "animal hospital.mp3". I have a...
1
KevinADC
by: KevinADC | last post by:
Note: You may skip to the end of the article if all you want is the perl code. Introduction Many websites have a form or a link you can use to download a file. You click a form button or click...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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...
0
Oralloy
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,...
1
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...
0
tracyyun
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...
0
isladogs
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...
0
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...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
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 ...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.