Help with php generated file.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
garyw74
Forum Newbie
Posts: 1
Joined: Thu Jun 09, 2005 10:18 am

Help with php generated file.

Post by garyw74 »

Hi

I am having some teathing problems with somne auto print label software. Very simple. Our Server generates a label via php and the user saves it to the desktop, the software recognises the file is their and prints it.

Problem I am having is this:-
If you save the file directly to the desktop the software says its a bad file. If you open the file then save it back to the desktop (without even making any changes) the software accepts the file and prints it.

I am guessing its how the php is closing the file. Can any one point me in the right direction.

Here is the code

header('Content-type: text/plain; charset=us-ascii');
header('Content-disposition: inline; filename=data.doc');
echo "ADD\n"; // 1 OPERATION
echo $order['customers_id']."\n"; // 2 The customer ID as held in WDM
echo $order['customers_name']."\n"; // 3 Business Name
echo "1\n"; // 4 Address Format
echo "\n"; // 5 Customer Name
echo $order['delivery_street_address']."\n"; // 6 Address Line 1
echo $order['delivery_suburb']."\n"; // 7 Adddress Line 2 (Optional)
echo $order['delivery_city']."\n"; // 8 Adddress Line 3 (Optional)
echo $order['delivery_state']."\n"; // 9 Town
echo $order['delivery_postcode']."\n"; // 10 Post Code
echo "UK\n"; // 11 Country
echo "RMRFC\n"; // 12 Service ID as held in WDM
echo ""; // 13 Contract ID
die();
break;



Thanks in advance Gary
User avatar
Burrito
Spockulator
Posts: 4715
Joined: Wed Feb 04, 2004 8:15 pm
Location: Eden, Utah

Post by Burrito »

please put your code in php tags...makes it much easier to read:

I would try changing the Disposition to attachment and add:

Code: Select all

header("Content-Description: File Transfer");
//also add a length header
header("Content-Length: ".$size);
edit: also, not sure if case sensitivity is an issue, but I've always done:

Content-Disposition:

and
Content-Type:
Syranide
Forum Contributor
Posts: 281
Joined: Fri May 20, 2005 3:16 pm
Location: Sweden

Post by Syranide »

Longshot, but the problems lies inside the delay, the server monitors for file changes and as fast as a file has been created it is read. Thus making notepad save file in an instant. Not even your computer would have time to blink ;)

However, when it comes to browsers, they create the file, check some headers, get the data, write it, and close. (no locking) The problem could be that it takes slightly too long for it to save the file, during which the server has already checked the file. (It might be that notepad locks files for reading while writing too, which browsers don't)

How you could possibly overcome this with the current solution I don't know. (unless you have access to the server source)

EDIT: try saving it to another folder then moving it to the desktop.

Longshot, but I would guess this is it. I've had similar problems myself.
Post Reply