You are here: Re: reading a var from another file « All PHP « IT news, forums, messages
Re: reading a var from another file

Posted by Paul on 05/26/05 23:30

Brian wrote:
> "Paul" <freelance@dezignage.net> wrote in message
> news:6%ole.1488412$8l.1142606@pd7tw1no...
>
>>Brian wrote:
>>
>>>"Paul" <freelance@dezignage.net> wrote in message
>>>news:Z_9le.1484742$6l.812316@pd7tw2no...
>>>
>>>
>>>>Brian wrote:
>>>>
>>>>
>>>>>This site I am working on is driving me up the F*****g wall ! , sorry
>>>>>just needed to get
>>>>>that of my chest
>>>>>
>>>>>I have site that run a MySQL query, there are many permutations of this
>>>>>query depending
>>>>>on what the users asks for (about 50 I think).
>>>>>
>>>>>I also need to save the queryed results into a CSV file and zip it on
>>>>>the fly. I have the
>>>>>code to do this (makezip.php), first of all I tried sending the MySQL
>>>>>query to makezip.php
>>>>>, this didn't work (see post Re: sending a MySQL query) so I am now
>>>>>trying a different way.
>>>>>
>>>>>search.php runs the search and displays the results on the screen. It
>>>>>also creates a var called $filedata,
>>>>>the var is the data to be zipped up
>>>>>
>>>>>makezip.php has the class to make the zip file.
>>>>>
>>>>>what I was trying to get the following to work........
>>>>>
>>>>>run the search.php, this give me the var $filedata I need. Have a link
>>>>>on this page to
>>>>>another file called savezip.php, this links runs another page called
>>>>>savezip.php that
>>>>>calls the below code.
>>>>>
>>>>>(the code needed to exicute making a zip file)
>>>>>
>>>>>include("search.php");
>>>>>include("makezip.php");
>>>>>
>>>>>$zipfile = new zipfile();
>>>>>$zipfile -> add_file($filedata, "test.csv");
>>>>>header("Content-type: application/octet-stream");
>>>>>header("Content-disposition: attachment; filename=newtest.zip");
>>>>>echo $zipfile -> file();
>>>>>
>>>>>I was hopping that when the link is clicked it run, it would read the
>>>>>var $filedata from the search.php
>>>>>and create the zip file for downloading, instead the savezip.php is
>>>>>reading in and displaying
>>>>>the search.php.
>>>>>
>>>>>I can't past the $filedata to save.php as its way to big, How can I get
>>>>>round this? How can I get the
>>>>>savezip.php to read the $filedata from search.php but without including
>>>>>the whole script?
>>>>>
>>>>>Once again thanks in advance,
>>>>>
>>>>>
>>>>>Brian
>>>>>
>>>>>
>>>>>
>>>>
>>>>Why don't you include your zipfile.php as part of search.php? then it
>>>>becomes one script and then you won't need to pass it anywhere... or have
>>>>your search.php at least create the zip file.. and then all you need to
>>>>pass is the URL of the zip file to your other file that the user can
>>>>click on and downlaod it from there...?
>>>
>>>
>>>The problem is that I need to change the headers when the script is
>>>called
>>>this way a pop up window appears to download the zip file. This zip file
>>>is done on the fly and no copies are made on the server so I can't put a
>>>link to it (done this way so the server does not get filled up with zip
>>>files)
>>>
>>>Brian
>>>
>>>
>>>
>>
>>I see.. I don't know how much data it is you're trying to pass from one
>>script to the other... but I would say you're best solution is to probably
>>use sessions... If still too big... I would recommend this solution for
>>you:
>>
>>#1. searc.php -> User searches for whatever it is they need... where they
>>have a link to download the content... the links points to your
>>zipfile.php (or whatever it was) ... which passes it the exact same search
>>query. Now zipfile.php is pretty much and identical copy of search.php
>>except all the output is held back and used for the zip file that will be
>>created in it.
>>
>>#2. Script takes all the output, (maybe you can even use the output
>>buffering functions in php if you don't need to change much of the output
>>that will be zipped up) and zips it up into the file....
>>
>>#3. First output to the browser is the proper headers for the download...
>>and the script sends it the zip file...
>>
>>I don't know if that makes sense.... but I think it could work...
>>
>>Take care,
>>
>>Paul
>
>
> Hi Paul
>
> passes the query was my first idea, but that didn't work (see my post
> Re: sending a MySQL query)
> I am now thinking of setting a cookie with the query in it, read it in, run
> it
> and the delete it.
> If that doesn't work, I'm running out of ideas !!!
>
> Thanks for your help mate
>
> Brian
>
>
>
Try something like this in your search.php

echo "<form name='download_zip' method='post' action='zipfile.php'>";
echo "<input type='hidden' name='query' value='{$query}' />";
echo "<input type='submit' name='submit' value='Download Zip' />";
echo "</form>";

you might just watch out that $query doesn't contain single quotes (for
this example) otherwise it will break the value attribute... maybe just
run the $query var through addslashes() or something like that... I'm
sure this could work for you..

then on zipfile.php you would just do something like this...

$query = !empty($_POST['query']) ? $_POST['query'] : null;

if(!$query) echo "Query didn't get passed!<br />";

..... do all your code for searching and zipping in here....

.... send the attachment headers.....

and that should do it no?

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация