[PHP] Reading in contents of URL

2002-08-02 Thread Mike C

I am trying to create a really simple proxy using PHP.

Basically, i need to:

1. read in the contents of a URL.
2. get the content-type
3. set the content type for the response
4. write the contents of the URL to the response.

here is what i have thus far:

$dataURL = http://www.foo.com/data.xml;;
$fp = fopen($dataURL, r);
$content = fread($fp, true);
echo($content);
fclose($fp);

I am running into two problems. One, the second param for fread takes 
the size of the file / content. how do i get this?

there is a comment at:
http://www.php.net/manual/en/function.fread.php

which says to just specify a constant and it will work, but what ever 
number i specify, that is the amount of data that is read.

how do i retrieve the content type?

thanks for any help...

mike c

[EMAIL PROTECTED]


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




[PHP] Submit/View images using PHP/MySQL

2002-01-29 Thread Mike C

Hi,

Can anyone point me to some good examples of how to add images using PHP 4 (from 
within a browser) to a MySQL database running on MacOSX, which is already configured  
working, then display the images by selecting their name or category etc, again within 
the browser. I also need to restrict the size of the file upload to approx  300kb

I found a good example at http://www.weberdev.com but it's a little too cut-down for 
me!

Thanks

Mike C
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Does anyone have the 'edit_member.php' script ....

2002-01-19 Thread Mike C

I have not been able to find an electronic copy of the above script that is in the 
book 'MySQL'.
Is anyone prepared to help me out. My, self-typed version contains a parse error that 
I cannot find?

Regards
Mike C
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Re: Does anyone have the 'edit_member.php' script ....

2002-01-19 Thread Mike C

It was suggested I send this to the list. The 'samp_db.inc' file follows this. The 
parse error is:
Parse error: parse error in /edit_member.php on line 11

#edit_member.php

?php
include (/users/mike/documents/include_files/samp_db.inc);
define (initial_page, 0);
define (display_entry, 1);
define (update_entry, 2);

function solicit_member_id ()
{
global $PHP_SELF;

printf (FORM METHOD=\post\ ACTION=\%s?action=%d\\n,
$PHP_SELF, DISPLAY_ENTRY);
print (Enter your membership ID number and password,\n);
print (then select submit.\nBRBR\n);
print (TABLE\n);
print (TR);
print (TDMember ID/TDTD);
print (INPUT TYPE=text NAME=\member_id\ size=10BR\n);
print (/TD/TR);
print (TR);
print (TDPassword/TDTD);
print (INPUT TYPE=password NAME=\password\ size=10BR\n);
print (/TD/TR);
print (/TABLE\n);
print (INPUT TYPE=\submit\ NAME=\button\ value=\Submit\\n);
print /FORM\n;
}

function display_entry ()
{
global $PHP_SELF;
global $member_id, $password;

$member_id = trim ($member_id);
if (empty ($member_id))
die (No member ID specified);
if (!ereg (^[0-9]+$, $member_id))
die (Invalid member ID specified (must be a number));
if (empty ($password))
die (No password specified);
if (check_pass ($member_id, $password))
$admin = 0;
else if (check_pass (0, $password))
$admin = 1;
else
die (Invalid password);

$query = SELECT last_name, first_name, suffix, email,
. street, city, state, zip, phone, interests,
. member_id, expiration
.  FROM member
.  WHERE member_id = $member_id
.  ORDER by last_name;
$result = mysql_query ($query)
or die (Cannot execute query);
if (mysql_num_rows ($result) == 0)
die (No user with member_id = $member_id found);
if (mysql_num_rows ($result)  1)
die (More than one user with member_id = $member_id found);

printf (FORM METHOD=\post\ ACTION=\%s?action=%d\\n,
$PHP_SELF, UPDATE_ENTRY);
 
hidden_field (member_id, $member_id);
hidden_field (password, $password);
print (TABLE\n);
$row = mysql_fetch_array ($result);
display_column (Member ID, $row, member_id, 0);

display_column (Expiration, $row, expiration, $admin);

display_column (Last name, $row, last_name, 1);
display_column (First name, $row, first_name, 1);
display_column (Suffix, $row, suffix, 1);
display_column (Email, $row, email, 1);
display_column (Street, $row, street, 1);
display_column (City, $row, city, 1);
display_column (State, $row, state, 1);
display_column (Zip, $row, zip, 1);
display_column (Phone, $row, phone, 1);
display_column (Interests, $row, interests, 1);
print (/TABLE\n);
print (INPUT TYPE=\submit\ NAME=\button\ value=\ Submit\\n);
print /FORM\n;

}

function check_pass ($id, $pass)
{

$query = Select password from member_pass where member_id = $id;
if (!($result = mysql_query ($query)))
die (Error reading password table);
if (!($row = mysql_fetch_array ($result)))
return (FALSE);
return ($row[password] == $pass);
}

function display_column ($label, $row, $col_name, $editable)
{
print (TR\n);
printf (TD%s/TD\n, htmlspecialchars ($label));
$value = htmlspecialchars ($row[$col_name]);
if ($editable)
{
$str = sprintf (INPUT TYPE=text NAME=\row[%s]\, $col_name);
$str .= sprintf ( VALUE=\%s\ SIZE=\80\\n, $value);
}
else
$str = $value;
printf (TD%s/TD\n, $str);
print (/TR\n);
}

function update_entry ()
{
global $row, $member_id, $password;

$member_id = trim ($member_id);
if (empty ($member_id))
die (No member ID specified);
if (!ereg (^[0-9]+$, $member_id))
die (Invalid member ID specified (must be number));
if (!check_pass ($member_id, $password)  !check_pass (0, $password))
die (Invalid password);
$result = mysql_query (select * from member where 1 = 0);
if (!$result)
die (Cannot query member table);

$query = Update member ;
$delim = set ;# put set before first column,, before others
while (list ($col_name, $val) = each ($row))
{
$query .= $delim $col_name =;
$delim = ,;

$val = trim ($val);
if (empty ($val))
{
if (nullable ($result, $col_name))
$query .= NULL;
else
$query .= \\;
}
else
$query .= \ . addslashes ($val) . \;
}
$query .=  where member_id = $member_id;
if (mysql_query ($query)  mysql_affected_rows ()  0)
print (Entry updated successfully.\n);
else
print (Entry not updated.\n);
}

function nullable ($result, $col_name)
{
for ($i = 0; $i  mysql_num_fields ($result); $i++)
{
if (!($fld = mysql_fetch_field ($result, $i)))
continue;
if ($fld-name == $col_name)
return (!$fld-not_null);
}
return (0);
}

if (empty ($action))
$action = INITIAL_PAGE;

$title = Historical League member editing form;
html_begin ($title, $title);

samp_db_connect()
or die (Cannot connect to the server);

switch ($action)
{
case initial_page:
solicit_member_id ();
break;
case display_entry:
display_entry ();
break;
case update_entry:
update_entry ();
break;


default:
die (Unknown action code ($action));
}

html_end ();
?

_


#samp_db.inc

?php
function samp_db_connect ()
{
$link = mysql_pconnect (localhost,username,password);
if ($link  mysql_select_db (samp_db))
return ($link);
return 

Re: [PHP] Re: Does anyone have the 'edit_member.php' script ....

2002-01-19 Thread Mike C

Hi Janet,


The problem is on this line.

print (INPUT TYPE=\submit\ NAME=\button\ value=\ Submit\\n);

There is a space between the \ and the  before Submit.

Yes indeed :-(, how could I miss that 

Your wonderful :-) Thank you (and others) so much.

Regards
Mike C
-- 


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




[PHP] Does any have the 'edit_member.php' script ....

2002-01-17 Thread Mike C

In electronic format that I can have? It is included in the book 'MySQL' by Paul 
DuBois ? I have a parse error in my script that I simply cannot find (after many, many 
tries).

TIA

Regards
Mike C
-- 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]