NameSilo

Fpassthru and an sql related question (NP$ rewards for working solution)

Spaceship Spaceship
Watch

Crusader

Established Member
Impact
6
#1) The following code seems to corrupt the file download if it's larger than 2MB (e.g. 4MB zip file gets corrupted), anybody have any ideas?
PHP:
    header("Content-Disposition: attachment; filename={$this->settings['realname']}");
        header("Content-Type: {$this->settings['mimetype']}");
//header("Content-type: application/octet-stream");
        header("Content-Length: {$this->settings['filesize']}");
//header("Connection: close");
        header("Pragma: no-cache");
        $fp = fopen(/path/to/download,"rb");
//$fp = fopen(/path/to/download,"r");
//        sleep(1);
        fpassthru($fp);
//print fread($fp,filesize(/path/to/download));
        fclose($fp);
        flush();
        exit();

I have the following enabled:
ini_set("memory_limit", "32M");
ini_set("max_execution_time","0");

-------------------------------------------------------------------

# 2 solved!
 
Last edited:
0
•••
The views expressed on this page by users and staff are their own, not those of NamePros.
Unstoppable DomainsUnstoppable Domains
you want to change "upload_max_filesize" in php.ini too.

To fit in the way you are doing it you could do:

PHP:
ini_set('max_upload_filesize', 8388608);
8388608 bytes = 8mb.

If that way does not work. I've never used it myself try making a .htaccess file with the following inside.
Code:
php_value upload_max_filesize 8M

I'm not sure I understand your second question.
 
Last edited:
0
•••
#2: Do you know the bounds (min and max values) for x and y?

SELECT * from table WHERE (x BETWEEN lowxvalue AND highxvalue) AND (y BETWEEN lowyvalue and highyvalue) ORDER BY x, y;
 
0
•••
paaaaaaaaaa said:
you want to change "upload_max_filesize" in php.ini too.

To fit in the way you are doing it you could do:

PHP:
ini_set('max_upload_filesize', 8388608);
8388608 bytes = 8mb.

If that way does not work. I've never used it myself try making a .htaccess file with the following inside.
Code:
php_value upload_max_filesize 8M

I'm not sure I understand your second question.

Does the upload size relate to the download? And my upload_max_filesize is at around 15mb right now I think.


enlytend said:
#2: Do you know the bounds (min and max values) for x and y?

SELECT * from table WHERE (x BETWEEN lowxvalue AND highxvalue) AND (y BETWEEN lowyvalue and highyvalue) ORDER BY x, y;

Example:
[7,7][7,8][7,9]
[8,7][8,8][8,9]
[9,9][9.8][9,9]

Max and min would be x+1 and x-1, y+1 and y-1.

Your select statement looks promising, but again, I'm not quite sure how to print out the individual results.

Note: I'll give out NP$ at the very end when I get at least one of them working.

Thanks!
 
0
•••
Example:
[7,7][7,8][7,9]
[8,7][8,8][8,9]
[9,9][9.8][9,9]

If you the starting value for x and y are the constant 7 and the ending value is the constant 9 then the statement would work hard-coded ...

$Querystring = 'SELECT * from table WHERE (x BETWEEN 7 AND 9) AND (y BETWEEN 7 and 9) ORDER BY x, y;'

If min-x, max-x and min-y and max-y are variables which get their value someplace earlier in the code, you can build your query string with the variables embedded:

$Querystring = "SELECT \* from table WHERE (x BETWEEN $min-x AND $max-x) AND (y BETWEEN $min-y and $max-y) ORDER BY x, y;"

To step through the resulting rows, first build $Querystring, then:

Connect to your database ... (I prefer to call this from a function outside my document root)

$conn = mysql_connect ("yourdatabasehost", "youruser", "yourpassword") or die ('Cannot connect to the database because: ' . mysql_error());
mysql_select_db ("yourdatabasename");
retrieve the query results...

$result_id = mysql_query ($queryStr)
or die("Cannot execute query string");
while ($row = mysql_fetch_row ($result_id)) {
do whatever to format the output here - columns of the current row will be an array in $row.​
}
mysql_free_result($result_id);
mysql_close($conn);

(Disclaimer: I'm writing this, as usual, while doing several other things - no guarantee that the above is completely free of stupid typo syntax-errors :) )
 
0
•••
#1: try adding this ini_set value too: ini_set("zlib.output_compression", "Off");

#2: If x and y are in a loop and incremented at the same rate... If your incrementing loop looks something like this, for example:

Code:
while($x<100){
     $x++;
     $y++;
}

then the query should look like:

Code:
$lower_bound=$x;
$difference=$x-$y;
while($x<100){
     $x++;
     $y++;
}
$sql='SELECT * FROM table WHERE x>'.$lower_bound.' AND x<'.$x.' AND y=x-'.$difference;

In this manner, x is within the bounds of the incremented values and y is compared to the returned db value of x minus the CONSTANT difference between x and y.

Of course, if $x and $y change at different rates, then please ignore my solution :).
 
Last edited:
0
•••
enlytend,

Your select query seems to be working best for me but I can't think of a way to output the following since the values wouldn't exist in the results form the query

Starting from 0,0

It shows up as:
[0,0][1,0][1,1]

I want it show up like this:
[n,n][n,n][n,n]
[n,n][0,0][0,1]
[n,n][1,0][1,1]


Right now, it can display the number values but I can't, yet, figure out how to keep it a 3x3 display. Obviously, it'll work fine if we start at 1,1 though.

----------------

mikesherov, I'll double check my zlib compression settings and get back to you.
 
0
•••
I want it show up like this:
[n,n][n,n][n,n]
[n,n][0,0][0,1]
[n,n][1,0][1,1]


Right now, it can display the number values but I can't, yet, figure out how to keep it a 3x3 display. Obviously, it'll work fine if we start at 1,1 though.

Now I'm confused. Are you saying you want it to output some blank cell if a value pair doesn't exist in the database? Need to keep each row to 3 cells? Or are there non-numeric values in the data which affect the sort order? Some other problem fetching the correct data? Do you need to know in advance how many rows will be retrieved or the max and min values in the database? Need to limit the # of rows retrieved?

If it's one of the first 2, it's easy to put logic into the "while" loop to account for that. In pseudocode:

whichcell=0; // increment this in the "while" loop to indicate if you're writing the first, 2nd or 3rd column. After writing the 3rd col, reset this value and close the </tr> (if you're doing a table layout). Open a new <tr> before writing the first cell.

last-x = x; (the start value, which may or may not be in the database)
last-y = y; (y start value, which may or may not be in the database)

while ($row = mysql_fetch_row ($result_id)) {

if ((($last-x + 1) < results-x ) or (($last-y +1) < results-y)) { // or this could be a "while" loop ...
generate cells as needed, incrementing last-x and last-y, until you get to the current results values
}
Output the current row values. Set last-x to the results-x, set last-y to results-y.

}​
 
1
•••
Ah, I didn't think about putting a loop in the results output! It looks like I can modify that one to work for me the best. I'm sending you NP$ for the help you've given me so far.

Thanks.


----------------

Now back to that fpassthru issue :(

I looked at what I had set php.ini intitially, here are my compression settings:

output_buffering = On
output_handler = ob_gzhandler
zlib.output_compression = Off

I have it set to gzip all pages automatically. I'm thinking that may be the problem but I don't exactly want to disable that as I'd have to setup ob handlers in all of my scripts to get them to gzip themselves. Any ideas? And yes, I've tried ini_setting output_buffering to off.
 
0
•••
[n,n][n,n][n,n]
[n,n][0,0][0,1]
[n,m][1,0][1,1]

I wrote the following to build a list of results to appear like the above.
Code:
// variables
/// note $x and $y would be defined as whatever
$xP=($x-1);
$width=9;
$height=9;
$yP=($y-1);
$xN=($x+1);
$yN=($y+1);
$cX=$xP;
$cY=$yP;

while($cX<=$xN){
	while($cY<=$yN){
		if(($cY>$width)||($cX>$height)||($cY<0)||($cX<0)){
			// doesn't exist so print out n and n
		} else {
			// print the values of x and y
		}
		$cY++;
	}
	$cY=$yP;
	$cX++;
}



Now... I want to do the same but with results gathered from the MySQL query below:
Code:
SELECT id,x,y,occupied,loc,type from sectors WHERE (x BETWEEN $xP AND $xN) AND (y BETWEEN $yP and $yN) ORDER BY x,y limit 9

Right now, all I can do is output the values that exist. It ignores the false results so I can't print out the "[n,n]."

Anybody have any ideas on how to plug the query into the code I wrote? I'm trying to restrict it to one query rather than doing 9 to verify if the numbers exist.

Another 50NP$ to anyone who can figure this out :D
 
Last edited:
0
•••
It sounds like you know before you start the query that the possible values are:

(x-1,y-1), (x-1,y), (x-1,y+1)
(x,y-1), (x,y), (x,y+1)
(x+1,y-1), (x+1,y), (x+1,y+1)

Is that correct? And you know the value of x and y before you query the database, right?

I've gotta a lot of "real work" to do this morning :) so I don't have time to explain this in detail, but ..

If you use this WHILE loop (where $queryStr is your SELECT statement):

$result_id = mysql_query ($queryStr)
or die("Cannot execute query string");
while ($row = mysql_fetch_row ($result_id)) {
(row output logic goes here)
}​

.. it will return the qualifying rows found in the database, one by one with each iteration of the WHILE loop.

If you know all the "expected" value pairs before you start, why not generate an array of them in advance? Then, inside the WHILE (database select) loop, check to see if the values in the current $row match the array pair you are expecting. If not, generate the (n,n) cells, walking the array until you get to the pair that matches the current $row values. Output the $row, set indices to the next array pair, let the WHILE loop reiterate.

You'll also need some code in case the 9th pair isn't in the database, or in case NONE of them are found.

Make any sense?

Glad I've been helpful so far :) ...
 
0
•••
I actually figured it out last night but thanks!

For anyone interested, I left the query the same as before but used my original script to display the sectors. I made some globals and displayed them as incremented array values. (e.g. $id[$i];).

I'm still looking for an answer to what's wrong with fpassthru, so if anybody has any ideas... my offer is still on the table.

Thanks everyone!
 
0
•••
Dynadot โ€” .com TransferDynadot โ€” .com Transfer
Domain Recover
DomainEasy โ€” Live Options
  • The sidebar remains visible by scrolling at a speed relative to the pageโ€™s height.
Back