php-general Digest 17 Jun 2005 11:54:59 -0000 Issue 3517
Topics (messages 217114 through 217125):
Re: question about system function call
217114 by: Richard Lynch
Re: Those checkboxes again
217115 by: Jack Jackson
Re: Retrievable weather service info?
217116 by: Rick Emery
Re: Delivery reports about your e-mail
217117 by: Sean Straw / PSE
Problem with array
217118 by: Ross
217119 by: Rory Browne
Re: undefined index
217120 by: Kim Madsen
Re: If I have 2 arrays...
217121 by: Jochem Maas
Re: [RE-PHRASE] PHP ZIP Class
217122 by: Jochem Maas
need help/sample code for php/apache/imagemagick
217123 by: bruce
217124 by: Rory Browne
Re: incrementing a register global
217125 by: Aaron Todd
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 ---
On Thu, June 16, 2005 2:43 pm, Tom Cruickshank said:
> I'm trying to do the following in php.
>
> system("/usr/bin/smbutil -v view //[EMAIL PROTECTED]")
>
> to be able to view some shares folders on a server.
>
> Unfortunately, if I use this command in console, I get prompted for a
> password.
>
> Is there a way in php to wait for a password and enter it automatically?
>
> Please let me know. Thanks!
smbutil may or may not accept a password as an argument.
Something like:
smbutil --password=SECRET -v view //[EMAIL PROTECTED]
If not, you MIGHT be able to do:
system("echo SECRET\n | /usr/bin/smbutil -v view //[EMAIL PROTECTED]");
You may need to dink around with the \n part to get it into the shell
rather than in the PHP string...
system("echo -e \"SECRET\\n\" | /usr/bin/smbutil -v view //[EMAIL PROTECTED]");
You should use exec instead during experimentation at least, so you can
get error messages... Actually, exec is probably better all around,
unless you really need passthru for performance reasons...
smbutil *might* require a TTY (a REAL logged in person) the way some
programs do. If its documenation says so, I think you're out of luck on
the password bit.
There might be other options, like SSH key-pair authentication or
Kereberos or, for all I know, somebody wrote a PHP Samba Module while I
wasn't looking... I'd probably never use it, so wouldn't have noticed.
--
Like Music?
http://l-i-e.com/artists.htm
--- End Message ---
--- Begin Message ---
Thanks, Joe!
I see what you weer going after. I had several problems including the
fact that I really didn't understand what I was trying to do until after
I did it. And I had some log errors a friend helped with.
What I needed to do was delete the media types from the intersection
table and then insert them anew; that way I don't have to do all sorts
of looping through finding the status of checked and unchecked boxes etc.
Eventually I came to:
if (isset($_POST['editrecordMedia'])){
if (!empty($_POST['media_types'])) {
//TO make sure art_id isn't empty
if (!empty($art_id)) { //delete media_art entries for this art_id
$query="DELETE FROM media_art WHERE art_id='$art_id'";
mysql_query($query);
$query = "INSERT INTO `media_art`
(`media_id`,`art_id`) VALUES ";
$sep = "";
foreach($_POST['media_types'] as $type)
{
$query .= "$sep ('$type','$art_id')";
$sep = ", ";
Anyway, thanks so much for your help!!
JJ
Joe Harman wrote:
if ($media_rows['art_id'] === $art_id) {
$checkbox_media[] .= "checked ";
}
$checkbox_media[] .= "/>{$media_rows['media_name']} ";
if think you only need 2 '=' signs... i do this alot with arrays of
check boxes .. now don't quote me on this... but i do something like
this.. using arrays for the check box values
if($permissions_data <> NULL)
{
if(in_array($row_rsPermissions['permission_short_name'], $permissions_data))
{ $checked_per = " checked"; } else { $checked_per = ""; }
}
hope that helps you out
Joe
On 6/16/05, Jack Jackson <[EMAIL PROTECTED]> wrote:
hi,
I'm severely frustrated and perhaps you can help with what I have done
wrong. The checkboxes I use to populate an intersection table work to
add the records, and now I am trying to update them. It's almost there
but producing some unexpected results when the form is submitted: the
idea is that it displays the checkboxes as pre-selected if they're
associated with the art_id in the intersection table. They're now
appearing as all unselected. Any help is appreciated.
<?php
$query = '';
$result = 0;
$art_id = $_POST['art_id'];
print_r($_POST);
if (isset($_POST['editrecordMedia'])){
if (!empty($_POST['media_types'])) {
foreach($_POST['media_types'] as $type)
{
$query = "UPDATE media_art SET
media_id='$type',
art_id='$art_id'";
var_dump($query);
mysql_query($query) or die(mysql_error());
}
}
else {echo "mediatypes is empty";}
//Closes if (!empty($media_types))
}//closes if (isset($_POST['editrecordMedia'])
//If editrecord hasn't been set, but selectcartoon has, get the
cartoon's recordset
//This is just to get the title for display purposes
$query = "SELECT art_title
FROM art
WHERE art_id='$art_id'";
//end
$media_query = "SELECT media.media_id,
media.media_name,
media_art.art_id
FROM media
LEFT JOIN media_art
ON media_art.media_id=media.media_id
AND media_art.art_id='$art_id'";
//These $art results are just to get the title for display purposes
$art_result = mysql_query($query);
$art_rows = mysql_fetch_assoc($art_result);
//end
$media_result = mysql_query($media_query);
$checkbox_media = array ();
while ($media_rows = mysql_fetch_assoc($media_result)){
$checkbox_media[] = "<input type='checkbox' name='media_types[]'
value='{$media_rows['media_id']}' ";
if ($media_rows['art_id'] === $art_id) {
$checkbox_media[] .= "checked ";
}
$checkbox_media[] .= "/>{$media_rows['media_name']} ";
}
?>
<table align="center">
<tr><th colspan="4">Main Menu</th></tr>
<tr>
<td><a href="addrecord.php">Add A Record</a></td>
<td><a href="chooserecord.php">Edit A Record</a></td>
<td><a href="deleterecord.php">Delete A Record</a></td>
</tr>
</table>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
name="editrecordMedia">
<input type="hidden" name="art_id" value="<?php echo $art_id ;?>">
Choose media related to <strong><?php echo
$art_rows['art_title'];?></strong><br /><br />
Media: <?php echo join($checkbox_media); ?>
<input type="submit" name="editrecordMedia" value="Update">
</form>
--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php
--- End Message ---
--- Begin Message ---
Quoting "Murray @ PlanetThoughtful" <[EMAIL PROTECTED]>:
Hi All,
Just wondering if anyone knows of a free weather service that can be
interrogated by PHP for information such as current temperature for a range
of cities around the world?
Regards,
Murray
I *highly* recommend the PEAR Services_Weather package:
http://pear.php.net/package/Services_Weather
"Services_Weather searches for given locations and retrieves current
weather data and, dependent on the used service, also forecasts. Up to
now, GlobalWeather from CapeScience, Weather XML from EJSE (US only),
a XOAP service from Weather.com and METAR/TAF from NOAA are supported.
Further services will get included, if they become available, have a
usable API and are properly documented."
hth,
Rick
--
Rick Emery
"When once you have tasted flight, you will forever walk the Earth
with your eyes turned skyward, for there you have been, and there
you will always long to return"
-- Leonardo Da Vinci
--- End Message ---
--- Begin Message ---
Yes, it would be nice if the list didn't relay this obvious cruft.
I'm s*bscribed to quite a few discussion lists, and php-general seems to be
the ONLY one relaying these malware messages and the claims of virus filters.
It looks rather like php-general is operating as an open list, seeing as
some of the addresses these messages are coming from clearly shouldn't
already be s*bscribed to the list, and the malware responsible for most of
it wouldn't actually perform a s*bscription.
At a minimum, I'd block the handful of known forgery addresses, plus block
postmaster@ and mailer-daemon@ messages from reaching the list. Yea,
bummer for the handful of people who use postmaster for their s*bscription
address (which is contrary to the purpose of the postmaster address, so no
loss there). I'd be quite happy if the list didn't accept attachments
either, but that would probably be a bit much to ask.
The appropriate solution would be to configure lists.php.net and any other
php.net mail hosts to use SMTP AUTH, and set them up with TLS certificates
and trusted relationships among one another using TLS (this is easy to do,
at least in sendmail - but php.net is running qmail...). After that is
done, set php.net hosts up to REJECT messages claiming to be from php.net
(proper AUTH or TLS will circumvent this rejection). End result: no more
forgeries through the php.net servers.
---
Please DO NOT carbon me on list replies. I'll get my copy from the list.
Founding member of the campaign against email bloat.
--- End Message ---
--- Begin Message ---
As with my previous post the problem is the pieces of the array can vary
from 1 to 4 items. So pieces 3 and 4 are often undefined giving the
'undefined index' notice. All I really want to do is display the array
pieces if they EXIST. But as they are inside a echo statement so I can't
even to a for loop...can I?
Any ideas?
R.
if ($quantity == 0){
}
else {
$pieces = explode(" ", $quantity);
$formatted_price = sprintf('%0.2f', $pricecode);
echo "<table width=\"240\" border=\"0\" cellpadding=\"2\"
cellspacing=\"5\"><tr><td valign=\"top\" align=\"right\"
width=\"40\">$pieces[0]</td><td align=\"left\" width=\"60\"></td><td
align=\"left\" width=\"200\">$pieces[1] $pieces[2] $pieces[3]
$pieces[4]</td><td valign=\"top\" align=\"left\"
width=\"80\">$formatted_price</td></tr></table>";
}
}
--- End Message ---
--- Begin Message ---
Not sure if it works for numeric indices, but maybe you could replace
$piece[3] with (array_key_exists(3, $piece) ? $piece[3] : ""). If you
want you could abstract that into a function, like
function array_access_element($key, $srch_array, $def=""){
return array_key_exists($key, $srch_array) ? $srch_array[$key] : $def;
}
On 6/17/05, Ross <[EMAIL PROTECTED]> wrote:
> As with my previous post the problem is the pieces of the array can vary
> from 1 to 4 items. So pieces 3 and 4 are often undefined giving the
> 'undefined index' notice. All I really want to do is display the array
> pieces if they EXIST. But as they are inside a echo statement so I can't
> even to a for loop...can I?
>
>
> Any ideas?
>
> R.
>
>
> if ($quantity == 0){
>
> }
> else {
>
> $pieces = explode(" ", $quantity);
>
>
> $formatted_price = sprintf('%0.2f', $pricecode);
> echo "<table width=\"240\" border=\"0\" cellpadding=\"2\"
> cellspacing=\"5\"><tr><td valign=\"top\" align=\"right\"
> width=\"40\">$pieces[0]</td><td align=\"left\" width=\"60\"></td><td
> align=\"left\" width=\"200\">$pieces[1] $pieces[2] $pieces[3]
> $pieces[4]</td><td valign=\"top\" align=\"left\"
> width=\"80\">$formatted_price</td></tr></table>";
>
>
>
>
>
> }
> }
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
> -----Original Message-----
> From: Ross [mailto:[EMAIL PROTECTED]
> Sent: Thursday, June 16, 2005 8:51 PM
> if ($quantity == 0){
>
> }
> else {
>
> $pieces = explode(" ", $quantity);
> $formatted_price = sprintf('%0.2f', $pricecode);
> echo "<table width=\"240\" border=\"0\" cellpadding=\"2\"
> cellspacing=\"5\"><tr><td valign=\"top\" align=\"right\"
> width=\"40\">$pieces[0]</td><td align=\"left\" width=\"60\"></td><td
> align=\"left\" width=\"200\">$pieces[1] $pieces[2] $pieces[3]
> $pieces[4]</td><td valign=\"top\" align=\"left\"
> width=\"80\">$formatted_price</td></tr></table>";
>
> }
> }
>
> The trouble is I get a NOTICE that tells me the indexes 1 to 4 have
not
> been defined. how do I do this.
Probably because $quantity IS 0, then the vars used in the else {} is
never set, but still in the script.
Try setting these before the if statement:
$pieces = array();
$formatted_price = 0;
$pricecode = 0; // this one is never set? Or set earlier in the script?
--
Med venlig hilsen / best regards
ComX Networks A/S
Kim Madsen
Systemudvikler/Systemdeveloper
--- End Message ---
--- Begin Message ---
Jason Barnett wrote:
Jay Blanchard wrote:
[snip]
Close... I think array keys are preserved from the (original) first
array, but other than that those appear to be the values that should
intersect.
[/snip]
After a var_dump I am seeing that there is an extra space in each
element of one array, so no intersection occurs.
Well then there you have it... having an extra space means that the
strings in the first array won't match the strings in the second array.
Perhaps you can array_intersect(array_walk($array1, 'trim'), $array2)
you'd want array_map not array_walk in this case:
array_intersect(array_map($array1, 'trim'), $array2)
also I found myself writing the following 2 funcs because the std
functions provided don't do what I 'mean'. e.g.:
array_intersect_assoc
array_intersect_key
array_intersect_uassoc
array_intersect_ukey
array_intersect
...etc
/**
* array_intersect_keys()
*
* returns the all the items in the 1st array whose keys
* are found in any of the other arrays
*
* @return array()
*/
function array_intersect_keys()
{
$args = func_get_args();
$originalArray = $args[0];
$res = array();
if(!is_array($originalArray)) { return $res; }
for($i=1;$i<count($args);$i++) {
if(!is_array($args[$i])) { continue; }
foreach ($args[$i] as $key => $data) {
if (isset($originalArray[$key]) && !isset($res[$key])) {
$res[$key] = $originalArray[$key];
}
}
}
return $res;
}
/**
* array_diff_keys()
*
* returns the all the items in the 1st array whose
* keys are not found in any of the other arrays
*
* @return array()
*/
function array_diff_keys()
{
$args = func_get_args();
$res = $args[0];
if(!is_array($res)) { return array(); }
for($i=1;$i<count($args);$i++) {
if(!is_array($args[$i])) { continue; }
foreach ($args[$i] as $key => $data) {
unset($res[$key]);
}
}
return $res;
}
--- End Message ---
--- Begin Message ---
Jay Blanchard wrote:
I am in need of a PHP class or script or something that will allow me to
like Richard mentioned - exec out to the shell and zip there....
I wrote a little/simple class when I was bored, here you go, HIH -
(sorry about the linewrapping)
I use the class in backoffice setting and it is actually used to
zip up PDF files, which is does just fine. (using zip on a RHES box)
<?php
/**
* Zipper.class.php :: wrapper for the system command 'zip'
*
* @author Jochem Maas <[EMAIL PROTECTED]>
* @version 0.1
* @copyright Copyright 2003-2004 iamjochem
*
* $Header: include/class/core/Zipper.class.php,v 1.2 2005/04/12 11:36:21
jochem Exp $
*/
abstract class Zipper
{
const ARC_RECURSE = 0x1; // zip will recurse the from directory for files
to include
const ARC_APPEND = 0x2; // zip will append to the given archive (if it
exists), rather than overwrite
const ARC_MOVE = 0x4; // zip will delete the archived files upon
success
const ARC_TEST = 0x8; // the generated cmdline will be returned as the first item of the output array instead
of being called - useful for checking what will happen (before you do it!)
/*
* WARNING: $pattern is the UNESCAPED file pattern to archive (defaults to
'./*')
* DO NOT ALLOW USER INPUT IN HERE WITHOUT SANITATION (e.g.
escapeshellargs() - bare in mind that
* strings which are quoted in the strings will not have globbing
performed, I say this
* because that is exactly the result of performing escapeshellargs())
*
* e.g. "'./*.xml'" instead of "./*.xml"
*/
static public function archiveData($fromdir, $todir, $filename, $pattern = '', $flags = self::ARC_RECURSE, &$output
= null)
{
static $msgs;
$fromdir = realpath($fromdir);
$todir = realpath($todir);
if (!is_dir($todir)) {
$output = array('"to" dir - directory not found');
return 19;
}
if (!is_dir($fromdir)) {
$output = array('"from" dir - directory not found');
return 19;
}
if (!self::checkforZIP()) {
$output = array('zip - command not found');
return -1;
}
/* could be localized via the Lang class */
if (!isset($msgs)) {
$msgs[ 0 ] = 'normal; no errors or warnings detected.';
$msgs[ 2 ] = 'unexpected end of zip file.';
$msgs[ 3 ] = 'a generic error in the zipfile format was detected. Processing may have completed
successfully anyway; some broken zipfiles created by other archivers have simple work-arounds.';
$msgs[ 4 ] = 'zip was unable to allocate memory for one or more
buffers during program initialization.';
$msgs[ 5 ] = 'a severe error in the zipfile format was detected.
Processing probably failed immediately.';
$msgs[ 6 ] = 'entry too large to be split with zipsplit';
$msgs[ 7 ] = 'invalid comment format';
$msgs[ 8 ] = 'zip -T failed or out of memory';
$msgs[ 9 ] = 'the user aborted zip prematurely with control-C (or
similar)';
$msgs[ 10 ] = 'zip encountered an error while using a temp file';
$msgs[ 11 ] = 'read or seek error';
$msgs[ 12 ] = 'zip has nothing to do';
$msgs[ 13 ] = 'missing or empty zip file';
$msgs[ 14 ] = 'error writing to a file';
$msgs[ 15 ] = 'zip was unable to create a file to write to';
$msgs[ 16 ] = 'bad command line parameters';
$msgs[ 18 ] = 'zip could not open a specified file to read';
}
/* check pattern - the pattern is meant to be expanded by the shell
(not by the zip binary) */
if (!($pattern = trim($pattern)) || $pattern == '.*') {
$pattern = './*'; /* everything */
}
//$pattern = escapeshellarg($pattern);
/* check flags */
$flagStr = array();
foreach(array(
self::ARC_RECURSE => '-r',
self::ARC_APPEND => '-u',
self::ARC_MOVE => '-m',
) as $cnst => $flag)
{
if ($flags & $cnst) {
$flagStr[] = $flag;
}
}
$flagStr = count($flagStr) ? join(' ',$flagStr): '';
$retval = null;
$cmd = "cd {$fromdir}; zip -v -T {$flagStr} {$todir}/{$filename}.zip
{$pattern}";
if ($flags & self::ARC_TEST) {
$output[] = $cmd;
} else {
@exec($cmd, $output, $retval);
if ($retval > 0) {
$output[] = '';
if (isset($msgs[ $retval ])) {
$output[] = $msgs[ $retval ];
} else {
$output[] = "\nunknown error [cmd: $cmd] (return: $retval)";
}
} else {
$output[] = "\nfiles archived successfully to zip file (return:
$retval)";
}
}
return $retval;
}
/* checks for the zip executable (assumes its on the path)
* the assumption is also made that the possible 'command not found' message
* is output in english!
*/
static private function checkforZIP()
{
static $check;
$check = true;
if (is_null($check)) {
$output = $retval = null;
@exec('zip -v', $output, $retval);
if (!array($output) || !count($output)) {
$check = false;
} else {
$check = stristr($output[ 0 ], 'command not found');
}
}
return $check;
}
}
designate a group of files to be zipped up, including PDF files,
automagically. It must be compatible with WinZip as that is what the
user will have access to. I have tried several things, a couple of
classes, and some other tricks to no avail. There seems to be an issue
with PDF's that I cannot figure out. The files are usually 1 byte too
short when you try to open them after unzipping them, and are therefore
corrupt.
If anyone is aware of something would you please let me know? I am even
willing at this point to add a couple of layers of abstraction to make
this work as long as the process is relatively invisible to the end
user. My desire is that it works like this;
User clicks link
[start automagic stuff]
*whirring* //determine which files should go into archive
*clicking* //put files in archive
[/end automagic stuff]
User presented with dialog box to save archive
Any and all clues are appreciated.
--- End Message ---
--- Begin Message ---
hi...
i'm considering creating a short test app/game to allow users to use their
mouse to select items from a given image/pic. i'd like to be able to take
some basic shapes, and construct an image/mosaic from them. i'd then like to
be able to display the image to the user, and have the user select various
shapes in the image.
i'd also like to be able to determine what 'shape' the user is selecting
within the image via the mouse coordinates...
any ideas as to how this can be quickly developed/thrown together for
testing...
i kind of thought that this should be doable with php/imagemajick as an
apache app..
thanks
-bruce
[EMAIL PROTECTED]
--- End Message ---
--- Begin Message ---
For the determining what part of the picture the user is refering to
I'd use image maps - which depending on your situation can be
serverside, or clientside.
I wouldn't bother with imagemagick, in this case, and just stick to gd.
On 6/17/05, bruce <[EMAIL PROTECTED]> wrote:
> hi...
>
> i'm considering creating a short test app/game to allow users to use their
> mouse to select items from a given image/pic. i'd like to be able to take
> some basic shapes, and construct an image/mosaic from them. i'd then like to
> be able to display the image to the user, and have the user select various
> shapes in the image.
>
> i'd also like to be able to determine what 'shape' the user is selecting
> within the image via the mouse coordinates...
>
> any ideas as to how this can be quickly developed/thrown together for
> testing...
>
> i kind of thought that this should be doable with php/imagemajick as an
> apache app..
>
> thanks
>
> -bruce
> [EMAIL PROTECTED]
>
> --
> PHP General Mailing List (http://www.php.net/)
> To unsubscribe, visit: http://www.php.net/unsub.php
>
>
--- End Message ---
--- Begin Message ---
Just so there is no confusion...I mistyped the line:
$names = substr(strrchr($_SERVER['QUERY_STRING'],"&"),7,1);
It should be a 5 instead of a 7 at the end:
$names = substr(strrchr($_SERVER['QUERY_STRING'],"&"),5,1);
--- End Message ---