Current location: Hot Scripts Forums » Programming Languages » PHP » Getting the created file (fopen/fwrite)


Getting the created file (fopen/fwrite)

Reply
  #1 (permalink)  
Old 02-14-04, 09:57 AM
Programme Programme is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
Getting the created file (fopen/fwrite)

I have a script where i want to export some information to a simple file, as shown under: (part of my function.php)

Code:
} if (!strcmp($cmd, "export")) {

     // The values to be written to file
     $values = "Title||Story||Cost||Value||Linka||Linkb";

     // Open file for writing
     $fp = @fopen("title.pmc","w") or die("Could not open file");

     // Write the config file
     $numBytes = @fwrite($fp, $values) or die("Could not write to file");

     // Close the config file
     @fclose($fp);

     header("Location: $HTTP_REFERER");
     exit;
}
This opens and writes the file, but what i want to do is to create this file temp, download the file, and then delete the created file if any!

So the file is only created and downloaded to the user, upon clicking the link, i really need some help with this one!

-------------
Programme
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 02-14-04, 10:21 AM
XxXoldsaltXxX XxXoldsaltXxX is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 28
Thanks: 0
Thanked 0 Times in 0 Posts
I think i see what your saying..
but its not clear.

If you are wanting to store the info (and have it as a diff file for every user) use
PHP Code:

$temp tmpfile();

$numBytes = @fwrite($fp$values) or die("Could not write to file"); // You dont have to fopen() a tmp file
fclose($temp); // This also deletes the temp file.. no mess to clean up later. 
If thats not what you were asking, please explain more.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #3 (permalink)  
Old 02-14-04, 10:32 AM
Programme Programme is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
What i want to do is this!:

The values you see are actually data from a MySQL table. These data is shown in a table. I then have a link called export!

This link will get the data, put it in a text file and give it to the user for download, i do not want the file just generated to be stored on the server!

If i use what you have written:

PHP Code:

$temp "title.pmc";

$numbytes = @fwrite($temp$values) or die("Could not write");
fclose($temp);

header("Location: $temp");
exit; 
Is this something that could work, but if you say the the fclose deletes the temp file, i will have to do the location before the fclose?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 02-14-04, 12:28 PM
NeverMind's Avatar
NeverMind NeverMind is offline
Community VIP
 
Join Date: Aug 2003
Location: K.S.A
Posts: 2,257
Thanks: 0
Thanked 2 Times in 1 Post
fclose() closes the file only!
I can see what you want, but do you think it's a good idea? because maybe the user has slow connection and the file is deleted before the file is completlly downloaded so he will not be able to continue downloading!
so you may want to delete the file after 1 hour or whatever time you want or leave the file until another user wants to download another file then delete the old file..
that's my opinion but it's up to you ..
__________________
PHPSimplicity
We don't need a reason to help people - Zidane [FF9]
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #5 (permalink)  
Old 02-14-04, 01:22 PM
Programme Programme is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
I am with you on the delete after a hours or whatever fits. Can you maybe give me an example on how to do this?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 02-14-04, 04:09 PM
Programme Programme is offline
Newbie Coder
 
Join Date: Dec 2003
Posts: 26
Thanks: 0
Thanked 0 Times in 0 Posts
I resolved the problem myself with som tips! By using header i ended up with this script that send a file to the user with some conent of your choise:

PHP Code:

<?php


$Buffer
='Title||Name||More stuff||mail';

header('Content-type: text/richtext; charset=UTF-8');
header('Content-Length: '.strlen($Buffer) );
header('Content-Disposition: attachment; filename="File.pmc"');

echo 
$Buffer;

?>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with my largest perl script. Grabbing data from a file. Sunnmann Perl 2 04-23-08 04:27 AM
Creating a 666 file? tsb PHP 11 02-09-04 04:12 PM
write to beginning of file or reverse an array of binary data abtimoteo Perl 1 01-20-04 11:09 AM
Please I Need help before all my hair is gone! LisatheNovice Perl 6 11-22-03 04:05 PM
Upload file type and size limiter! Arctic ASP 1 08-02-03 08:06 PM


All times are GMT -5. The time now is 07:27 AM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.