php-general Digest 12 Oct 2005 14:51:47 -0000 Issue 3733

Topics (messages 223940 through 223962):

Re: Sequential multiple file download?
        223940 by: Oliver Grätz

Re: Store a variable name in a database field.
        223941 by: Oliver Grätz

trouble with generating the file attachment
        223942 by: Ricardo Ferreira

help me in creating tables on the fly
        223943 by: Suresh Pandian
        223944 by: Jochem Maas
        223945 by: Jasper Bryant-Greene

include file to global scope
        223946 by: Claudio
        223947 by: Jochem Maas
        223955 by: Claudio
        223962 by: Claudio

Check if an url is a jpg image
        223948 by: Tommy Jensehaugen
        223949 by: Richard Davey

Re: Run a php script as a separate thread/process
        223950 by: Tommy Jensehaugen

Hidden Form Help
        223951 by: Alnisa Allgood

Userlogin system seems to override the if statement....
        223952 by: twistednetadmin
        223960 by: Mark Rees

Issues with backslashes and GET data
        223953 by: Martin Selway
        223954 by: Brent Baisley
        223961 by: Chris Shiflett

pear.php.net
        223956 by: Claudio
        223957 by: David Robley

Report generators
        223958 by: Anakreon Mendis

Re: getting php to generate a 503
        223959 by: Chris Shiflett

Administrivia:

To subscribe to the digest, e-mail:
        [EMAIL PROTECTED]

To unsubscribe from the digest, e-mail:
        [EMAIL PROTECTED]

To post to the list, e-mail:
        [email protected]


----------------------------------------------------------------------
--- Begin Message ---
This can't be easily done. The natural way of doing this would involve
sending some HTTP headers but this is not possible once you've started
sending data for the first file.

The hard way of doing this is a 2-way approach where you have two
connections: a data connection and a control connection. This of course
requires you to use JavaScript. The control connection to the server
would periodically be asking if sending a download has finished. This
could be done with Ajax techniques and some kind of server side database
or session store for the information about the finished downloads. The
other connection would then be triggered as a redirect from JavaScript
that fires up another download.

Of course there might be other solutions but none of them are really
easy to implement. If you are targeting a closed audience you might
change your approach to sending some kind of download list that triggers
a download manager.


AllOLLi
____________
Byers: "What proof do you have?"
Bond: "I got this!"
Byers: "You're on the phone, Jimmy!"
[Lone Gunmen 09]

--- End Message ---
--- Begin Message ---
Yep, code sample, please. Your question is not describing your problem
clearly enough.

OLLi
____________
If at first you don't succeed, call it version 1.0

--- End Message ---
--- Begin Message ---

Hi,

 

I have the two files which I send as an attachment. One is simple form with a file upload box. The other is the corresponding PHP file which sends the information via e-mail. I used the code provided here (http://pt.php.net/de/imap_mail_compose) but something must be wrong. Perhaps you can provide me with some explanation

 

Thanks

 

RF


--- End Message ---
--- Begin Message ---
hello friends,
 
im currently working on creating musical forum.....
i need to create tables for every song uploaded on the fly to save the comments 
and rates entered by the viewers.
im unable to create tables on the fly.........
can anyone know how to create tables on the fly .........plz tell me .........
Also, can u tell me the way to how to play the song using php......
i uploaded the songs to mysql database...
if u know the same kind of work  anywhere  in the net as tutorials and help 
.........plza tell me the URL........
 
Thanks to all..................
 
Suresh.P

                
---------------------------------
 Yahoo! India Matrimony: Find your partner now.

--- End Message ---
--- Begin Message ---
Suresh Pandian wrote:
hello friends,
im currently working on creating musical forum.....
i need to create tables for every song uploaded on the fly to save the comments 
and rates entered by the viewers.
im unable to create tables on the fly.........

...............................

if I upload 1000 songs to your server then that will ammount to a 1000 tables. 
and a 1000
songs is nothing.... the whole idea of creating a table for every song is wrong 
and will get you
into trouble (100,000 songs will crash your system), you only need one table to 
store
all the comments for each song - and possible one extra table to store the 
rates for all songs.

can anyone know how to create tables on the fly .........plz tell me .........

all you need to do is generate an sql query with the CREATE TABLE syntax. and 
then run it
the same way you would run a normal query - thsi assumes that youre database 
actually allows
the relevant user to create tables.

Also, can u tell me the way to how to play the song using php......
i uploaded the songs to mysql database...
if u know the same kind of work  anywhere  in the net as tutorials and help 
.........plza tell me the URL........

Google for 'Database design' 'Data Normalization' and stuff like that - you 
seem to be in need
of knowledge regarding how to create a half decent database (one that wont bite 
you in the ass)

Thanks to all.................. Suresh.P

                
---------------------------------
 Yahoo! India Matrimony: Find your partner now.

--- End Message ---
--- Begin Message ---
Suresh Pandian wrote:
im currently working on creating musical forum..... i need to create
tables for every song uploaded on the fly to save the comments and
rates entered by the viewers. im unable to create tables on the
fly......... can anyone know how to create tables on the fly
.........plz tell me ......... Also, can u tell me the way to how to
play the song using php...... i uploaded the songs to mysql
database... if u know the same kind of work  anywhere  in the net as
tutorials and help .........plza tell me the URL........

AHHH! Don't create a table for every song!!!! Have a `songs` table containing all of the songs. Something like:

CREATE TABLE songs (songID INT UNSIGNED NOT NULL AUTO_INCREMENT, artist VARCHAR(50) NOT NULL, title VARCHAR(50) NOT NULL, PRIMARY KEY(songID));

(simplified) and another table `comments` like this:

CREATE TABLE comments (commentID INT UNSIGNED NOT NULL AUTO_INCREMENT, songID INT UNSIGNED NOT NULL, comment TEXT NOT NULL, PRIMARY KEY(commentID), KEY(songID));

and another `ratings` like this:

CREATE TABLE ratings (ratingID INT UNSIGNED NOT NULL AUTO_INCREMENT, songID INT UNSIGNED NOT NULL, rating TINYINT UNSIGNED NOT NULL, PRIMARY KEY(ratingID), KEY(songID));

That's why it's called a *relational* database. If you're using InnoDB you can even define the relations between the tables using foreign keys. Go to http://dev.mysql.com/doc/en/mysql/ and have a good read of the MySQL manual, it will be very helpful for you.

Please don't just copy-paste the above table definitions, they're meant to be modified to suit your needs.

I'll leave your other question to be answered by someone with experience of streaming audio from PHP, as I've never had occasion to do that.

--
Jasper Bryant-Greene
Freelance web developer
http://jasper.bryant-greene.name/

--- End Message ---
--- Begin Message ---
Hi,

I'm using PHP 5. I have a class operation that includes php files.
Is there a way to include this files to global scope? So that difined vars 
and functions are global accesseble?

I saw that some PHP functions have a context parameter, is something like 
this in "eval" or "include" possible?

Thanks,

Claudio 

--- End Message ---
--- Begin Message ---
Claudio wrote:
Hi,

I'm using PHP 5. I have a class operation that includes php files.
Is there a way to include this files to global scope? So that difined vars and functions are global accesseble?


first off I would recommend that you 'pollute' your global scope as little as
possible.

secondly could you describe what you are trying to do and why exactly -
stuff like this has been solved before but its hard to recommend a strategy when
one doesn't know what the underlying idea/direction is ....

that said the solution will probably involve the use of the 'global'
keyword.


I saw that some PHP functions have a context parameter, is something like this in "eval" or "include" possible?

I think you mean then 'context' param related to functions that work with
streams - this is not AFAIK related to [variable] 'scope'.

also eval() sucks (unless there is no other way to do something, in which case
its lovely ;-).


Thanks,

Claudio

--- End Message ---
--- Begin Message ---
> first off I would recommend that you 'pollute' your global scope as
> little as possible.
I agree at all! Thats my opinion, and i don't use global variables at all. 
The problem is, other people do. And if I need to use their code I must 
include it.

> that said the solution will probably involve the use of the 'global' 
> keyword.
Yes, see example files 1 and 2. This files are very simple, but shows the 
problem. Naturly the decision what file to include an when is complexer than 
that.
The file2.php represents a large standalone "old" php file. Doesn't maintend 
by me. It works fine.
The file1.php5 represents a newer application. File2 will not work, because 
$abc is not a global var.
Ok, I could search for all declared vars and add a global to it. Thats not 
realy a "nice" solution.

Do anyone have a better Idea?

Claudio

file1.php5:
-----
<?php
class testInc {
public static function incFile($x) {
return include_once($x);
}
}
testInc::incFile('file2.php');
?>
-----
file2.php:
-----
<?php
$abc = true;
function anotherOne() {
global $abc;
if ($abc) {
echo 'it works';
} else {
echo 'failure';
}
}
anotherOne();
?>
-----

--- End Message ---
--- Begin Message ---
Is it possible to process the file in second php instance?
An only get its output?

Claudio 

--- End Message ---
--- Begin Message ---
Hi,
Is it possible to check if an url is a jpg image from php?

Thank you for your help.

Cheers,
Tommy 

--- End Message ---
--- Begin Message ---
Hi Tommy,

Wednesday, October 12, 2005, 10:48:55 AM, you wrote:

> Is it possible to check if an url is a jpg image from php?

#1 Quick and unreliable: Check if there is a .jpg or .jpeg as the final
characters of the URL string.

#2 Bit more complex, very expensive: fopen() the URL, download the
content to a temporary location, inspect it with native php functions
like getimagesize. If your PHP config allows, you can probably perform
a getimagesize directly on the URL, but I've not tried this.

#3 Trickier, less expensive than #2, but balls-on accurate: fopen()
the URL (after suitable validation) and grab the header (the first few
KB). JPEG files are easily identified, but come in a variety of
flavours.

http://www.codeproject.com/bitmap/iptc.asp

Cheers,

Rich
-- 
Zend Certified Engineer
http://www.launchcode.co.uk

--- End Message ---
--- Begin Message ---
Thank you very much. This is what I ended up with if anyone needs it:

<?php
function runSeparateThread($strHost, $strPath="/") {
 $fFile = fsockopen($strHost, 80, $intError, $strError);
 if ($fFile) {
  $out = "GET ".$strPath." HTTP/1.1\r\n";
  $out .= "Host: ".$strHost."\r\n";
  $out .= "Connection: Close\r\n\r\n";
  if(!fwrite($fFile, $out)){
   $result = "runSeparateThread():fwrite(). Could not write:'".$out."'. 
Host:'".$strHost."'. Path:'".$strPath."'";
  } else {
   $result = true;
  }
  fclose($fFile);
 } else {
  $result = "runSeparateThread():fsockopen(): Could not connect to 
".$strHost." (".$intError.") ".$strError.".";
 }
 return $result;
}
?> 

--- End Message ---
--- Begin Message ---
Hi-

I'm in a situation where I'm required to deal with a hidden form. The
background details are exhausting, but the gist is: one form is
auto-generated and lacks proper formatting. It was part of an open
source package that DID NOT allow templating. So to keep using the
application engine, but provide formatting, I created a CSS class to
hide the unformatted form while displaying the formatted form.

When submitting data to the database this doesn't seem to cause any
issues. It accepts data based on the fieldvalues and ids. But when
retrieving data to repopulate the form, what happens is that the
hidden form gets the values and the displayed form does not.

http://nahic.ucsf.edu/phpESP/survey.php
login= Wisconsin

Basically, if you complete the required field (state), fill out some
random data, hit save, then select "resume" from the info page
provided. You'll get back an empty form. But if you look at the code
you'll see that the hidden form has the values.

So I have a few questions:

1) Is there anyway to echo data from one field to the next, especially
if the field (name or id) are exactly the same??  (i.e. field=state
value=Wisconsin; if the field state is then repeated somewhere else on
the page, can the value, Wisconsin, also be automatically repeated.

2) If yes, to the above can PHP do this and how? or is this something
requiring Javascript or some other coding.

--- End Message ---
--- Begin Message ---
I'm new to this. So I used a tutorial to write this. But it shows "Login ok.
Welcome" at once when the page loads. Here is the tutorial:
http://www.ss32.x10hosting.com/ss32/files/PHP-logins.pdf
<?php
include ("DBconnection");


session_start();
$err = 0;
echo $err; //just to check. Shows 0
$sql_login = sprintf("SELECT 'name', 'pass' FROM DB
WHERE 'name'='%s' AND 'pass'='%s'", @$_GET['name'],@md5($_GET['pass']));
$login = mysql_query($sql_login) or die(mysql_error());
if (mysql_num_rows($login) == 0) {
$GLOBALS['MM_username'] == @$_GET['name'];
echo $err; //just to check. Shows 0
session_register("MM_username");
echo $err; //just to check. Shows 0
$err = 1;


}
echo $err; //just to check. Shows 1
?>
<!-- Form -->
<?php
if ($err != 1) {
if ($err == 2) { ?>
There was an error processing your login.
<?php } ?>
<table>
<form action="<?php $_SERVER['PHP_SELF']; ?>" method="get">

<tr>
<td align="center" valign="middle" class="maintext">
Login as:<input name="name">
</td>
</tr>
<tr>
<td align="center" valign="middle" class="maintext">
Password:<input name="pass" type="password"><br>
</td>
</tr>
<tr>
<td align="center" valign="middle" class="maintext">
<input type="image" src="images/login_btn.jpg" value="login"></td>
</tr>
</form>
</table>

<?php
}else{
?>
Login ok. Welcome <?php
echo "<meta http-equiv=Refresh content=3;url=1stpage.php>";
}
?>

I don't get any further. I must be missing something, but what??

Please help.

-Tore W-

--- End Message ---
--- Begin Message ---
-----------------------------------------
sorry my mail reader didn't indent. comments in ----------
----------------------------------------

I'm new to this. So I used a tutorial to write this. But it shows "Login ok.
Welcome" at once when the page loads. Here is the tutorial:
http://www.ss32.x10hosting.com/ss32/files/PHP-logins.pdf
<?php
include ("DBconnection");
session_start();
$err = 0;
echo $err; //just to check. Shows 0
$sql_login = sprintf("SELECT 'name', 'pass' FROM DB

-----------------------------
This is going to return
name pass
If you take the quotation marks away, you will select the actual field
values
-----------------------------

WHERE 'name'='%s' AND 'pass'='%s'", @$_GET['name'],@md5($_GET['pass']));

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

Never send user input directly into the database. Read up on sql injection
to find out why
-----------------------------

$login = mysql_query($sql_login) or die(mysql_error());
if (mysql_num_rows($login) == 0) {
$GLOBALS['MM_username'] == @$_GET['name'];
echo $err; //just to check. Shows 0
session_register("MM_username");
echo $err; //just to check. Shows 0
$err = 1;


}

echo $err; //just to check. Shows 1

<!-- Form -->
<?php
if ($err != 1) {
if ($err == 2) { ?>
There was an error processing your login.
<?php } ?>
}else{
?>
Login ok. Welcome <?php
echo "<meta http-equiv=Refresh content=3;url=1stpage.php>";
----------------------------------------

you will end up here if $err==1
Since you set $err=1; just before the if block begins, this is as expected.
You might find the section on if statements in the PHP manual has some
useful examples which might make things clearer:

http://uk2.php.net/if


The tutorial you are following is a bit ropey to be honest if this is the
dtandard of the code in it.

----------------------------------------
}
?>

--- End Message ---
--- Begin Message --- I use a php page which is supposed to return records from a database table limited to the servername specicified in a drop down menu.
A servername may contain a backslash e.g. Server1\SQL1.
When this data is returned from the URL e.g. $server = $_GET['server'];
The name is returned as Server1\\SQL1, so the search fails.

I've tried using a regular expression to remove one of the backslashes:
$server = ereg_replace("\\", "\", $server);
but I can't get this to work either.

Any suggestions welcome, I'm running out of ideas.

Martin

--- End Message ---
--- Begin Message --- Have you tried the stripslashes() function? That will "unescape" characters that have been escaped.

On Oct 12, 2005, at 8:03 AM, Martin Selway wrote:

I use a php page which is supposed to return records from a database table limited to the servername specicified in a drop down menu.
A servername may contain a backslash e.g. Server1\SQL1.
When this data is returned from the URL e.g. $server = $_GET ['server'];
The name is returned as Server1\\SQL1, so the search fails.

I've tried using a regular expression to remove one of the backslashes:
$server = ereg_replace("\\", "\", $server);
but I can't get this to work either.

Any suggestions welcome, I'm running out of ideas.

Martin

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




--
Brent Baisley
Systems Architect
Landover Associates, Inc.
Search & Advisory Services for Advanced Technology Environments
p: 212.759.6400/800.759.0577

--- End Message ---
--- Begin Message ---
Martin Selway wrote:
A servername may contain a backslash e.g. Server1\SQL1.
When this data is returned from the URL e.g. $server =
$_GET['server']; The name is returned as Server1\\SQL1,
so the search fails.

Sounds like magic_quotes_gpc is enabled. Disable it.

I've tried using a regular expression to remove one of
the backslashes:
$server = ereg_replace("\\", "\", $server);

There is a function called stripslashes() that does this. Also, you should not use a regular expression function when matching literal strings. Regular expressions are for matching patterns. Use something like str_replace().

Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

--- End Message ---
--- Begin Message ---
is http://pear.php.net offline?

<snip>
Warning: Invalid argument supplied for foreach() in 
/usr/local/www/pearweb/include/pear-format-html.php on line 360

Warning: Invalid argument supplied for foreach() in 
/usr/local/www/pearweb/include/pear-format-html.php on line 360

Warning: Invalid argument supplied for foreach() in 
/usr/local/www/pearweb/include/pear-format-html.php on line 360

Warning: Invalid argument supplied for foreach() in 
/usr/local/www/pearweb/include/pear-format-html.php on line 360

Fatal error: Call to undefined function: init_auth_user() in 
/usr/local/www/pearweb/include/pear-format-html.php on line 112
</snip> 

--- End Message ---
--- Begin Message ---
Claudio wrote:

> is http://pear.php.net offline?
> 
> <snip>
> Warning: Invalid argument supplied for foreach() in
> /usr/local/www/pearweb/include/pear-format-html.php on line 360
> 
> Warning: Invalid argument supplied for foreach() in
> /usr/local/www/pearweb/include/pear-format-html.php on line 360
> 
> Warning: Invalid argument supplied for foreach() in
> /usr/local/www/pearweb/include/pear-format-html.php on line 360
> 
> Warning: Invalid argument supplied for foreach() in
> /usr/local/www/pearweb/include/pear-format-html.php on line 360
> 
> Fatal error: Call to undefined function: init_auth_user() in
> /usr/local/www/pearweb/include/pear-format-html.php on line 112
> </snip>

Very much online, but until someone fixes the code....


Cheers
-- 
David Robley

People own dogs. Cats own people.

--- End Message ---
--- Begin Message ---
I was looking for a report generator library and found a good one
called agata.
What I need (and the library does not provide) is the ability to
export the generated report in doc and excel format.
The library does exports the reports in openoffice Write format
but this would require to post-process the generated file in order
to convert it into doc.
As for excel, a possible solution would be to use the CSV format
but is not a good solution either.
Does anybody knows any other library which exports into pdf,doc and
excel formats?

Thank's in advanced.
Anakreon
-- 
Three words describe our society:homo homini lupus

--- End Message ---
--- Begin Message ---
[EMAIL PROTECTED] wrote:
I want to write a php page that can return a 503 with some useful
information.
<?php

header("HTTP/1.0 503 Service Unavailable");
echo "Page execution failed.\n";
?>

Is what I've done so far - yet it doesn't work

You need to elaborate or define what "works" means to you, because my first assumption is that it works just fine. What behavior are you wanting?

By the way, LiveHTTPHeaders is pretty useful for examining HTTP:

http://livehttpheaders.mozdev.org/

Hope that helps.

Chris

--
Chris Shiflett
Brain Bulb, The PHP Consultancy
http://brainbulb.com/

--- End Message ---

Reply via email to