Tracking Forums, Newsgroups, Maling Lists
Home Scripts Tutorials Tracker Forums
 
  HOME    TRACKER    PHP




Create A Csv File On-the-fly For Downloading


I have a large database-created table on a page, that needs to have a "download as csv file" link (actually, as xcel, but I'll bet that's much harder to create).

What's the simplest way to do that? Do I actually delete-and-recreate a csv file on the server every time?




View Complete Forum Thread with Replies

See Related Forum Messages: Follow the Links Below to View Complete Thread
Downloading File
I was trying to download a file which I have created in the server. I was successful enough to retrieve it by using the header function but unfortunately, the content has been changed. Instead of the data that I inserted in it, it was changed into a html codes.


Downloading A File
How would I let someone download a file blah.extension, where the file contains something that is made in the script? For example:

Grab database info
Make coding
Send it as blah.extension

I don't know how to send it as blah.extension, I've tried header type, but I'm not sure how to get the exact extension.

Ftp File Downloading...
im developing a site now... which capable of uploading files from client machine.. after downloading files... the creator/ client are capable of reviewing its uploaded documents.. guided by href links as a direct link to its file..... but my problem is how can i downloaded those files from the ftp?

i try href="/folder/file.doc"> file.doc [/url] == > but the browser says "The website declined to show this webpage"

Downloading A File
I do not have many experience with PHP.

What is the way to download a file? In my website I want to give
access to my users to downlaod several files.

Downloading A File...with Php3?
can anyone tell me how to download a file with php3 onto the server?

Downloading Exe File Does Not Work
I have a link in my page that allows users to download an exe file.
However, when I download and run it, it briefly displays the DOS box and
nothing happens. In my php file, I have:

header("Content-Type: application/octet-stream");
header("Content-Disposition: atachment; filename=$filename");
header("Content-Length: ".filesize("$path/$filename"));
header("Pragma: no-cache");
header("Expires: 0");
$fp=fopen("$path/$filename","r");
print fread($fp,filesize("$path/$filename"));
fclose($fp);
exit();

Am I missing something?

Also, if I click on the download again, after downloading it already, it
displays garbled text on the screen.

Downloading Php Code Instead Of File
I have a website where I can upload a file via a form. The uploaded
file is stored in a MySQL database. When dloading te file I get a save
as... dialog box, letting me save the file. But when it is dloaded and
I open it, it contains te HTML code of the file displayed...
Wordt thin g is - it _used_ to work so the code is OK - only some
little thing changed. Maybe the header part?

global $HTTP_GET_VARS, $connection;
$nodelist = array();
// Pull file meta-data
$SQL = "select * from filemetadata where id = '" .
$HTTP_GET_VARS[ID]."'";
if (!$result = mysql_query($SQL, $connection))
die("Failure to retrieve file metadata:L ".$php_error);

if (mysql_num_rows($result ) != 1)
die("Not a valid file id!");

$FileObj = mysql_fetch_array($result);

// Pull the list of file inodes
$SQL = "SELECT id FROM filedata WHERE
Masterid='".$HTTP_GET_VARS[ID]."' ORDER BY id";

if (!$result = mysql_query($SQL, $connection))
die("Failure to retrieve list of file inodes");

while ($CUR = mysql_fetch_object($result))
$nodelist[] = $CUR->id;

ob_end_clean();
ob_start();

// Send down the header to the client
Header ( "Content-Type: ".$FileObj[Datatype]);
Header ( "Content-Length: ".$FileObj[Size]);
Header ( "Content-Disposition: attachment;
filename=".$FileObj[Name]);

// Loop thru and stream the nodes 1 by 1
for ($i = 0 ; $i < count($nodelist) ; $i++) {
$SQL = "select FileData from filedata where id =
'".$nodelist[$i]."'";

if (!$result= mysql_query($SQL, $connection))
die("Failure to retrieve file node data");

$DataObj = mysql_fetch_object($result);
echo $DataObj->Filedata;
}
}

Automatic File Downloading
When a user clicks on a certain link, the file opens when he has a registered program for that file type. For example: if I click on a link to a .doc-file, it opens in Word, if I click on a .gif-file, it opens in my browser.

Does anyone know how to download a file automatically, no matter what programs are installed, so that even .html-pages are downloaded in stead of shown? Guess it can be done by sending an alternative header with the file, but don't know how to do it exactly.

Downloading An Uploaded .doc File
I am working on a site in which some members may browse/upload a Word document and other members may wish to download these and view them. I have tried saving the uploaded file like..

if (!copy($cv, "cvs/cv".$cid.".doc") ) {
echo("Problems encountered receiving your CV. However your application will still be processed.");}

and the download link like...

<A HREF='<?="/cvs/cv$cid.doc"?>'><B>View</B></A>

..and the browser opens Word and the file gets displayed. This is taking FAR to long to happen. What would be ideal is to simply click on the link and get the normal download dialog up. I also tried..

if (!copy($cv, "cvs/cv".$cid) ) {
...} and to view..

<A HREF='<?="/cvs/cv$cid"?>'><B>View</B></A>

..but I got a download dialog asking if I wanted to download CVxxx.txt but I need CVxxx.doc. Any ideas? I want to be prompted to download a Word Doc.

Downloading A Fraction Of The File
I ahve a download script that is only downloading a fraction of the file. can anyone point me to a tutorial/script that will enable me to understand headers and what is required.

Downloading A File From Another Site
I want to be able to have a script on mysite(http://mysite.com) to download a file from another site(http://downloadsite.com).  I wrote a script where you enter the location of a file (http://downloadsite.com/song.mp3) and click "fletch file" it well get the file and allow you to download it.  But it takes forever it seems like it transfers to my websever first before the dialog pops up so i can download it.  Heres the code:

Downloading From Another Server(txt File).
Can someone tell me how I can get a txt file, or its contents this way:
Running a cron every 30 minutes, get file contents or download the txt file.
Save it on sever.

Saving/downloading A Dynamic File
Is there a way of making a PHP script go to a URL, like
www.somedomain.com/file?id=2, and saving the dynamic file that is created?

I want to run this script in crontab, so it downloads the file every hour. I have tried using wget, but that doesn't seem to save the dynamic file created, it just saves the blank HTML page "file?id=2".

Downloading A Dynamically Built File
i'm trying to build a comma-separated file for my users to download summaries of information in the database. i did it once before and it worked fine, but this time it's in the context of a frameset and there are some problems. i have a form that calls the test script below, and the form's target is a hidden frame in my frameset. Code:

Server Not Downloading Complete File
i have a php script that creates a file.  this part works fine - it always writes 100% of the data to this file. the next part of this script is letting the user download that file. when i run it on my localhost, everything is fine and 100% of the file is there. however, when i run it on a different server, for some reason when you download the file, it always gets cut off at 2000000 bytes.

so the file that gets downloaded can be much smaller than the original file. is there something i need to change in the php.ini file or any other suggestions? this is my download.php code:

$file=$path.$_GET['file'];
header("Content-type: application/force-download");
header("Content-Transfer-Encoding: Binary");
header("Content-length: ".filesize($file));
header("Content-disposition: attachment; filename ="".basename($file).""");
readfile("$file");

PHP File Downloading Instead Of Showing Results In Browser.
I'm sure all the guru's know this one, but I cannot find it. I just
installed Luinx. I configured Apache and got everything up and
running.

When I do my PHP test, it asks me to download the file, rather than
displaying the info on the screen.

Now, I added the following lines to the httpd.conf:

LoadModule php4_module /usr/lib/httpd/modules/libphp4.so

AddType application/x-httpd-php .php .php3 .php4 .phtml
AddType application/x-httpd-php-source .phps

DirectoryIndex index.html index.php index.html.var

And I restarted the server........no good. It displays HTML documents,
but not PHP documents.

Downloading File Via Curl When Url Not A Direct Link?
I am trying to use CURL to log into a site, download a file, and send the results. So far I have gotten it to log-in and send results (based on sample data), but I cannot get the file to download.

For example, the url is in a format similar to the link below When you click it, it redirects somewhere and provides REPORTS.ZIP (note the bolded area of the example link).

http://www.example.com/file.php?date=2006/01/18&date2=2006/01/19&file=REPORTS&info=all

The problem is that the url is not a direct link and when clicked, it prompts any (standard) browser to download the (zip) file. When I tried using wget, it downloads file.php which does no good.

What do I need to do for it to download and write the file to my local directory?

Downloading Multiple Files In Single Zip File
I am developing the project management system.

Each Project:
1. Title, description ... , stored in mysql database
2. Upto ten files (initial description), (name in db, file in file
system)
3. Message board, stored in mysql database (1 file per message, message
in db, file in file system)

I need a link (Download Project) which will download all the project
related files, description, message board in the single zip file.

Downloading File Stored In Mysql Table Through Ssl
I have a table where I store some binary data. To retrieve this
information as a downloadable file, I use the following code:

header('Content-Type: $mimeType');
header("Content-length: $size");

// for filename, i store the filename in the table, so this does not
actually
// point to a physical file name on the file system
header("Content-Disposition: attachment; filename=$fileName");
header("Content-Description: PHP Generated Data");
echo $data;
return true;

If I go through a normal port (http), the file downloads no problem.
When I try this through ssl (https), I get the following error:

'Internet Explorer cannot download / from 192.168.0.9.'

Through port 80, the filename is set correctly. Through ssl, the
filename doesn't seem to be getting set. Is there a problem with
using 'Content-Disposition: attachment' through ssl?

Downloading File Via Curl When Url Not A Direct Link?
I am trying to use CURL to log into a site, download a file, and send the results. So far I have gotten it to log-in and send results (based on sample data), but I cannot get the file to download and write to the server.

For example, the url is in a format similar to the link below When you click it, it redirects somewhere and provides REPORTS.ZIP (note the bolded area of the example link).

http://www.example.com/file.php?date=2006/01/18&date2=2006/01/19&file=REPORTS&info=all

The problem is that the url is not a direct link and when clicked, it prompts any (standard) browser to download the (zip) file. When I tried using wget, it downloads file.php which does no good. What do I need to do for it to download and write the file to my local directory?

Check If Someone's Still Downloading A File On My Server?
i have a script that creates a temporary zip-file on my server, that a user can download.
but this file must be deleted after a while. so i wondered if there's a way to check if someone s still downloading the file.

Hiding Download Location When Downloading File From Server?
I have a requirement where we need to sell online the survey reports which are stored on our server in .pdf formats. Now i have two options once the payment is made i can directly give the client a link to download the file, which would reveal the download location to the client which can be reused by others too.

Second option is to copy the file to a temporary dir and then pointing the download link to that dir and lateron deleting the file from the temporary folder. But in this case i would have to setup a cron job to daily remove all the old files from the dir. i am not comfortable with this idea.

Is there any other way to do this? Can i be notified by php when the download is completed at the users end so that i can delete the file from temp folder once its done (using the same download script instead of running a cron job later).

Refer To A File Outside The Website Tree For Downloading Purposes
I'm using Linux Redhat 8.0 (LAMP).
I have a file tx.zip , that is placed in /tmp.
Now I want people to be able to download this file without copying it to
the website tree
Can I make a reference like http://www.website.com/../../../tmp/tx.zip
if the root of my website is /var/www/html/Vwebsite ?
Due to restrictions, I cannot copy the file to /var/www/html/Vwebsite

Browser Unable To Send Another Request While It's Downloading A File From PHP Page.
While I am downloading a mp3 file from php page, browser freezes and
is not able to send any request and get the response using ajax until
the file gets completely downloaded. As soon as the file downloading
finishes, the browser gets all the responses it is waiting for (which
are sent after the file download starts)....

Having Connection Timeout Problem When Calling A Php Script While Downloading A File From The Same Server.
My dot net client downloads files and checks for any new files time to
time. The server is apache2.0.53 server. So what happens is that my
file download thing works fine if I dont try to call any page from the
server while downloading. If I try to call a single page while
downloading a file then the page request goes time out and the server
then closes the existing download stream and the client doestn't throw
any exception. So many a time I end up with incomplete downloaded file.
The server side code is in PHP and every thing like calling a page or
downloading a file is done by calling some PHP script.

What is the reason behind this type of behaviour.Has this anything to
do with PHP and server settings.

Downloading Php File Rather Than Indicated Pdf File.
I am trying to download a generated pdf file from the server to the local machine. However, when running the script :

header("Content-type: application/pdf");
header("Content-disposition: attachment; filename=driverpdf.pdf");
header("Content-Length: " . filesize(FIRSTBASE."/images/graphs/driverpdf.pdf"));
header("Pragma: no-cache");
header("Expires: 0");
readfile(FIRSTBASE."/images/graphs/driverpdf.pdf");

return;

It downloads 'index.php'.  Has anyone seen this and do they possibly know what could be going on?  I don't understand why it's doing this, and can't find an explanation.

Can Php Create A New Txt File?
I'm trying to build an e-card page for a client using php, but they don't want to use a mySQL database, so I was wondering if PHP can create new text files when someone enters their information into a form and then the recipient gets an email with that txt file reference in a link and can then go to a page that populates with that particular text.

Does it sound like I'm on the right path?

Can't Create New File
I have a small PHP script that will convert text into vcard format and write it to a new .vcf file (plain text). To write, I've used PHP Code:

How To Create A File Using PHP ?
How to create a file using PHP ?

Cannot Create File When Uploading
Hi. I use this script to upload file (taken by Zend.com website)
This works locally, but when i upload to server i get an error.
script...

//$campofile is the file field filled before in a form...

$archive_dir = "../folder1";
$filename = basename($campofile_name);
$filesize = basename($campofile_size);
$filetype = basename($campofile_type);
if($campofile!='')
{
if(!copy($campofile,"$archive_dir/$filename"))
echo "Error: $filename could not be uploaded."."<br>";
}

After executing that script i get this error:

Create Ms Word File With Php
I wanna to create ms word (.doc) file with my data from php.

Cannot Upload And Create File
I've written this script to upload files to my server, and if the file being uploaded is an image file, a thumbnail is automatically created along with it.

But right now, after you select the file, and hit upload, you are brought to a blank screen. I check the directories, and the files are not uploaded. Everything LOOKS right, I just don't know what's wrong. PHP Code:

Telling PHP To Create A New File
is there a way i can tell php to create a new file with the name , for example, "hello". With the extension ".TXT" ?

How To Create Wsdl File
how can I create wsdl file for soap server what do I need to define.

How Do I Create An Url That Downloads An Mp3 File?
i want to write a script that lets me create a url that downloads an mp3 file like this: http://domain.com/songs.php?m=killerfx

and have that goto this file http://domain.com/music/abc.mp3 this is what I have so far, could someone help me with the missing part?

<?php
$m = $_GET['m'];
$file = 'music/'.$m.'.mp3';?>

Create Downloadable Xml File
I need to make a downloadable xml google sitemap based off of mysql data. What fuctions would I use. I assume I would be using fopen to write it, but how do I make it downloadable. I don't want there to be a copy of it on the server (permissions wouldn't allow it anyway), I just want people to hit a button, generate the file, and download it.

Create A Table Regarding A Text File
I have this .txt file :

Roger|tow25$rank259
Isabelle|tow36$rank24
Pascal|tow12$rank29
Sergeï|tow45$rank5
Michel|tow1245$rank45478
Frédéric|tow1$rank125425

And this programm php3
<?php
$fichier = "classeur.txt";
if($fp = fopen($fichier,"r")){
$ligne=1;
echo "<table border=1 bordercolor="#00CCFF" width=500>
";
echo "<tr align=center><td colspan=3>TITRE</td>";
while (!feof($fp)) {
list( $name, $tampon ) = explode( "|tow", $fp );
list( $tow, $obj ) = explode ( "$rank", $tampon );
echo " <tr>";
echo "<td
align=center><b>Nom".$name."</b></td><td>Tow".$tow."</td><td>Obj".$obj."</td[color=blue]
>";[/color]
echo "</tr>
";
$ligne++;
echo "</table>
";
echo "$cell";
fclose($fp);
}else{
echo "Error : open impossible ".$fichier;
exit();
}
?>

I would like to past each value of the lines in the tex file, in 3 variables
$nom; $tow; $obj
and create a table with 3 column ( column 1 the name, in 2 the tow, and in 3
the obj)

Create A Table In MySQL From A .php File
Is it possible to create a mySQL table from a .php file? If so how?

Use Form Data To Create XML File?
I like to create a form in an HTML page that will use the data entered into it to display an XML file. Code:

Script To Create Html File
I'm looking for a php script that will look in my images folder and for each image in there, create an html file named <imagename>.html and store it in a folder called "pages". I currently use the code  inserted below that scans my image folder, creates an xml file that contains a list of the images and the my Flash image gallery reads the xml file to create the gallery.

but I would rather do it by the method I'm requesting above and get away from flash. Any ideas? Even if there's a way to modify the code below to do what I want, that would be great. Code:

Create Db Firebird With Php, Exec Does Not Want To Execute A File .bat
I am trying to create db firebird with php, script php generates and executes a file .bat . the file .bat creates db using isql in c:firebirdin, but .bat does not create db when is called by php script, but the file .bat if it works when it is executed from MSDOS, creates db correctly,

the question is ¿why the file .bat creates the data base when it is executed by MSDOS but it does not work when is executed by exec in php script? as php script can execute .bat to create db? PHP Code:

How Do You Create A New Line Each Time A File Is Written To?
I am trying to write user submitted information to a file, and I am having a little problem. Here is my code:

<?php
import_request_variables($_POST, "FirstName");
$file=(/fname.dat');
$f=fopen($file,'a');
fwrite($f,$FirstName);
fclose($f);?>

Each time the file gets written to, the info is just tacked right after the last character from the previous entry. How can I get this to write each entry on a seperate line?

PHP Script To Create MySQL DB From A Dump FIle
I just need to write a script that will read a dump file and just create the tables, ect. as specified from it. If anyone has a link or some simple code for this that would be great. Didn't think about this till i had done it, but i have the mysql create commands over multiple lines, so I can't just use:

while (list($lineNum, $line) = each($dumpFile)) {
mysql_query($line);}

Using Fopen() To Create New File - Works For A Few Then Just Doesnt
I am currently working on a content management system where a user can
fill in a form (title, keywords, link text etc. - all the initial
attibutes), which when submitted, will go onto create a web page.

The code is as follows:

$html = "<html>
<body>
<p>Hello World</p>
</body>
<html>";
$handle = fopen($_SERVER['DOCUMENT_ROOT']."/path/to/folder/".$filename,
"w");
fwrite($handle, $html);
fclose($handle);

Pretty basic, I think. I works for a few and then it just stops. I get
no error to say that 'could not create file' or 'file not found', it
just submits. Any reason for this? I have tried searching the C: drive
for the file but it cannot be found.

At the moment Im trying to figure out when it actually occurs but for
some annoying reason, it seems to be working now. I would prefer to be
assured that it wont occur again so just thought I would still post
something here just encase this problem is a known one.

Is fopen() the best solution for creating files? I was aware that it
was used to open an existing file but create one (?). Is this what it
was intended to do? Im sure it is, but its new to me.

Create A Search Result On A File Directory
I am working on a project where I need to take a variable from a form, then match that variable against a directory list and return a modified list of files available that are clickable.

I have created the form - (easy part)
and I have found coding that pulls the directory list.

I am having trouble finding information on how to take that directory list a sort the results based only on the keyword that was typed in.

Read Off An Uploaded File Name To Create A Link?
I want to read an uploaded filename, say "mypic.jpg" to create a link to this image without having to ask the users to enter the filename "mypic.jpg" when uploading it.  My upload code works file but it's not on the same page. 

I'm working on my "index.php" page and included the upload.php page "<?php include("upload.php"); ?>" in it.  Here's the sample of my code in the upload.php page (the code for the form is separate and not included here): Code:

Upload File And Create Directory For Each User?
I just saw an interesting thread, for uploading files - but my problem is just to add a directory for each user, the user name are stored in session variable sess_uname?

I am not sure how do i check if the directory is already exists for the logged user.  if directory exists than i i just want to move the file to that directory otherwise create directory with the name as sess_uname and store the file. Code:

PHP5, Win2003, Create Any File Or Folder On The Server
If I create any file or folder on the server and run the php file it
works with no problem. As soon as I copy a website from another
server onto this one none of the php code works and the browser only
shows the actual php code.
Is there a permission I need to set? I have never had this problem...

Need To Create Drop Down Box With Data Pulled From Text File
Trying to make a drop down box like this example:

Dog
Cat
Bird

But sometimes I will need to update it...and add/remove names from the list. I want to do it fast and easy and I don't want to use a MySQL Database. I'd rather use a text file...can that be done? I would keep the info in a text file and then push it to a drop down box via php and html.


Copyright © 2005-08 www.BigResource.com, All rights reserved