Re: [PHP] Q: Use getImageSize() on image data from email?

2002-12-05 Thread Morgan Hughes
On Thu, 5 Dec 2002, Mans Jonasson wrote:

 Hi all,
 I am trying to use getImageSize() on imagedata I am receiving in an
 e-mail and collecting with imap_fetchstructure() et al. What I have in
 my $image variable is just the actual image data - no headers or
 anything, and of course getImageSize() doesn't work that way.
(snip)

  The imageCreateFromString() function may help you here, this is exactly
  what it's for.  Unfortunately many people have had trouble with it.  In
  your situation, I'd write the thing out to a temporary file.

  In that case I'd consider using ImageMagick's identify command rather
  than getImageSize(), since it handles many more image types.  Depending
  on what you need you may find the -verbose option helpful, as it gives
  tons of information, but is slow...

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356




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




Re: [PHP] PHP includes without access to the default directory

2002-12-05 Thread Morgan Hughes
On Thu, 5 Dec 2002, Gundamn wrote:

 I have a hosted account. As such, I am unable to use the default location
 for files when used with the include command. So could somebody tell me how
 I can either make it go to a different directory, or to link to something
 (and how to add the variable as the filename)?

 Thank you in advance.

  My usual approach is to have an includes/ directory, at the same level
  as the htdocs/ directory, and thus outside the webspace.  In this
  includes/ directory I put an include.php file which includes any other
  files needed with include_once, like so:

  ?
include_once INC_DIR . '/config.php';
include_once INC_DIR . '/functions.php';
  ?

  In htdocs/ I put another include.php, which basically says:
  ?
define ('INC_DIR', '../includes');
include INC_DIR . '/include.php';
  ?

  In any subdirectories of htdocs/ I put a similar file, except one level
  deeper it'd be:
  ?
define ('INC_DIR', '../../includes');
include INC_DIR . '/include.php';
  ?

  For each subdir level, add a ../ to the define.

  On a hosted account, you may instead have to put your includes/
  directory elsewhere.  In this case, the include.php in htdocs/ would
  just be
  ?
define ('INC_DIR', '/path/to/includes');
include INC_DIR . '/include.php';
  ?

  and the sub-directory scripts just
  ?
include '../include.php';
  ?

  Either way, the goal though is to have an include.php file in each
  directory of your webspace that references a single include.php file
  with relative (../) paths.  Coupled with keeping your includes outside
  the webroot, this can make include files a lot less troublesome.

  A bit of overhead, true, but it keeps my configs, db passwords, and
  library code entirely out of the webspace.  I've used it successfully in
  a large site (150 user-accessible scripts, 25 library scripts, totalling
  about 1M of php)

  One big warning about include files... PHP's include functions work
  counter-intuitively in that all relative paths are relative to the
  script that caught the user's request.  Thus if you have a bunch of
  scripts in a lib/ directory, they can't include each other without
  taking into account the path from the calling script...  Thus why I try
  to define INC_DIR as early as possible if it's relative.

  Hope this helps...

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356




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




Re: [PHP] Re: invalid range

2002-12-02 Thread Morgan Hughes
On Mon, 2 Dec 2002, Nick Eby wrote:

 looks like because you have a dash inside your character class; when inside
 a character class the dash is a special character and you'd have to escape
 it
 eregi(^([a-zedv_\.\- ]+)$, $value);

  Traditionally in regexes, a dash has to come last, otherwise the regex
  engine interprets it as a range.  Escaping it may work too, but I've
  never had trouble moving dashes to the last char in the range, so your
  regex would look like this:
eregi(^([a-zedv_\. -]+)$,$value);

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356





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




Re: [PHP] Browser going to page twice?

2002-12-02 Thread Morgan Hughes
On Mon, 2 Dec 2002, Leif K-Brooks wrote:
 I'm having a weird problem.  When I go to a page on my site, it often
 goes twice.  I'm not sure if this is a client-side or server-side
 problem, but it doesn't happen on other sites.  Is this a common
 problem, or am I making some dumb mistake?

  Is it the index.php of a directory?  Often if you go to
http://server/directory
  Apache rewrites that to
http://server/directory/
  with a Location header or some such.  If entering it in your browser
  with the slash fixes it, that's the one.

  Modern browsers seem to automatically add a slash if you just put in
www.domain.com
  as part of converting it to
http://www.domain.com/
  but for subdirectories there is often a redirect.

  hope this helps!

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356



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




Re: [PHP] Browser going to page twice?

2002-12-02 Thread Morgan Hughes
On Mon, 2 Dec 2002, Leif K-Brooks wrote:
 Nope, it happens on all of the pages, but it seems to be fairly random.
 It doesn't happen all of the time, just sometimes.

  You're using what server...  Apache I hope?  There is an Apache
  directive (in 1.3 at least) that controls whether the server sends back
  replies with the name it was called by, or the official name of the
  server.  UseCanonicalName and ServerName may be the answer.  I've seen
  this effect with those options using authentication...

  If not that, then I don't have a solution, but I sure admire the
  problem! ^_^

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356



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




Re: [PHP] PHP and the PDFlib

2002-12-02 Thread Morgan Hughes
On Sun, 1 Dec 2002, Ryan Smaglik wrote:

 Has anyone found any other means of opening an existing pdf file and adding
 text to it?  The only thing I could find is the  PDI + PDFlib commercial
 combo which I do not have the $1000 to dish out right now...
 Any Ideas?

  While the PDFlib/PDI combo is the only way that's actually been stated
  to work...  It bears remembering that PDF files are modified Postscript,
  and tools to convert PDF to/from Postscript do exist.  Perhaps you can
  build something by converting the PDF to PS, which should be text you
  can read and manipulate, then convert back to PDF.  The utilities I'm
  thinking of are ps2pdf and pdf2ps, which seem to be part of the
  Ghostscript package and ship with most Linux distros...

  Hoep this helps!

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356



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




Re: [PHP] last updated ?

2002-11-30 Thread Morgan Hughes
 Dumb question here but whats the general practice regarding putting a
 website last updated: entry on a web page? Does the web master manually
 enter in today's date in a database table entry and let PHP display. Is it
 statically added to the HTML page? Etc...
 If you want website last updated then from a database sounds OK but
 where I'm working its commonly a page last updated wanted. In this
 case its just a manually entered date in html in the page.

  Or use stat() to get the page's mtime, something like

  ?
$stat = stat($HTTP_SERVER_VARS['SCRIPT_FILENAME']);
$date = strftime(%c, $stat[9]);
print Last update: $date;
  ?

  Which will be automatically updated...

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356



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




Re: [PHP] test for ascii or binary string

2002-11-29 Thread Morgan Hughes
On Fri, 29 Nov 2002, Jonathan Sharp wrote:

 Is there a way to determine if a string has ascii or binary data in it?

  I've used this kind of approach in the past to determine which encoding
  to use on a string which may contain text or an image.  Basically it
  uses addcslashes to escape non-ASCII chars, then strips all
  non-backslash chars, and takes the size of the string...  $size should
  contain the number of bytes (out of 1024) that were escaped, and should
  be very low for clean text, and pretty high for binary.  This was made
  for analyzing blobs, but maybe the approach is useful...


  $text = addcslashes(substr($string, 0, 1024), \\\'\0..\37\177..\377);
  $size = strlen(preg_replace('/[^]/', '', $text));
  if ($size  200)
print mostly text, use addslashes;
  else
print mostly binary, use base64_encode;


-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356



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




Re: [PHP] Streaming audio

2002-11-27 Thread Morgan Hughes
On Wed, 27 Nov 2002, Mako Shark wrote:

 Does anyone know how to do streaming audio with PHP?
 No clue if this is even possible. I've checked around
 a bit, looked at some script sites, but nothing seems
 to give a clue. I *think* it might be possible to set
 something like this up, but I'm not sure.

  Streaming how?  I've got a PHP script that plays MP3 files off the disk
  through an HTTP stream, that might be useful for you to start with.  I
  wrote so I could figure which MP3s were being played regularily, versus
  ones that could be deleted.  You could probably extend it by reading
  from some FIFO on your server, that another process was writing the MP3
  stream into, though you'd lose the ability to seek in it...  Mail me
  direct if you're interested.

  It includes the shoutcast metadata for updating the stream title as it
  goes, however it appears winamp ignores this data unless the response
  from the server is ICY/1.0 200 OK rather than the HTTP 200 OK...  As
  far as I can tell after checking the SAPI source and asking here, it's
  not possible to override that.

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356




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




Re: [PHP] Streaming audio

2002-11-27 Thread Morgan Hughes
On Wed, 27 Nov 2002, Tom Culpepper wrote:

  I had no idea this would be of interest to so many people...  I've
  now posted it on a server for download; it's at
http://kyhm.com/tmp/mp3-example.php.gz
  for anyone who's interested.

  There's a bunch of commented-out calls to a dprint() in the script; this
  is a function I use for syslog-based debugging.  Obviously you can't
  print debugging output to a MPEG stream!  A replacement could be cobbled
  together that looks something like this:

$dprint_file = '';
function dprint ($msg)
{
  global $dprint_file;
  if (!$dprint_file)
$dprint_file = fopen(/tmp/mp3.log, a);
  fprintf ($dprint_file, %s, $msg);
}

  Good luck, and if anyone makes something useful out of this, I'd like to
  hear about it!

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356







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




Re: [PHP] Re: testing for empty array

2002-11-26 Thread Morgan Hughes
On Tue, 26 Nov 2002, Kyle Gibson wrote:

  I have an array $keywords, how do I test to see if it is empty?
  $keywords == '' seems to throw out an error.

 Maybe...

 if(count($keywords) = 0)
 {
   //...
 }

  I use sizeof(), which apparently is an alias to count(), and it works
  fine, so count() should do the trick.

  if ( !sizeof($keywords) )
print keywords is empty;

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356



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




Re: [PHP] imagecopyresized

2002-11-25 Thread Morgan Hughes
On Mon, 25 Nov 2002, adrian [EMAIL PROTECTED] wrote:

 hi
 i'm having problems resizing jpegs.
 here's an e.g. using manual example.
 code used :
 ?
 $new_w=395;
 $new_h=297;
 header(Content-type: image/jpeg);
 $dst_img=ImageCreate($new_w,$new_h);
 $src_img=ImageCreateFromJpeg($name);
 
ImageCopyResized($dst_img,$src_img,0,0,0,0,$new_w,$new_h,ImageSX($src_img),ImageSY($src_img));
 ImageJpeg($dst_img);
 ?

 and the result can be seen here.
 http://www.sitestogo.biz/temp/test.php
 i'm wondering if it's to do with the gd library installed.

  Try it with ImageCreateTruecolor(), since ImageCreate() produces 8-bit
  indexed-color images...  If that function doesn't exist, you're using a
  pre-2.x GD, and those can't do 24-bit images at all...

  Good luck!

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356



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




Re: [PHP] imagecopyresized

2002-11-25 Thread Morgan Hughes
On Mon, 25 Nov 2002, adrian [EMAIL PROTECTED] wrote:

 sorry.i included the link so you can see the result
 it's difficult to explain what it looks like without including
 attachments - which is a worse idea i think!
 there are no errors it just looks bad.
 i didn't know that imagecreate() produces 8-bit images.
 this implies that with older versions of gd ( 2.x) you can't
 manipulate jpegs? gd is my only option.
 adrian

  You can read and produce JPEGs with GD  2.x, but any JPEG you read is
  stripped to 8-bit, with as many colors as the reader can allocate.  Any
  JPEG you produce will be 8-bit as well.

  GD stayed at 2.0.1 for quite a while (a year or more), which was a beta
  and had some serious bugs, but now it's being maintained again, and is
  up to 2.0.8...  Unfortunately the PHP extension is broken and
  requires specific patches, so GD 2 support probably won't be widespread
  with ISPs until it's sorted out and stable...  So you'll have to wait,
  or look into something like ImageMagick.

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356



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




RE: [PHP] getting mysql dump using php

2002-11-23 Thread Morgan Hughes
On Sun, 24 Nov 2002, Rich Gray wrote:

 Answer is No. 2)
 Use cron to run the mysqldump utility instead of a php script.
 Let me know if you need more info.

  I use this one with crontab, it works pretty well, if your email program
  can handle uuencode:


#!/bin/sh
# File: db_backup.sh
# Descript: Runs a ful mysqldump of one or more MySQL databases, uuencodes
#   and compresses them, and mails them to a specified address.
#   Requires mysqldump, gzip, uuencode, mail or mailx, and crontab.
#
#   Normally this run from crontab, with an entry like:
# 0 3 * * * sh ~/db_backup
#
# Version : 1.00
# Author  : Morgan Hughes ([EMAIL PROTECTED])
# License : Copyright (C) 2002, Morgan Hughes.  Use freely.


# Account/password/email info
db_list=your_database
db_user=your_username
db_pass=your_password
email=your_email_addy

# program locations
mysqldump=mysqldump
dump_opts=
uuencode=uuencode
gzip=gzip
mail=mail

# Actual code
for db_name in $db_list ; do

date=`date '+%Y%m%d-%H%M%S'`
$mysqldump $dump_opts -u $db_user --password=$db_pass $db_name | \
$gzip -c9 | $uuencode $db_name-$date.sql.gz | \
$mail -s DB backup, $db_name, $date $email

done

# Ends: db_backup.sh



  At home I have a script plugged into .procmailrc with an entry like:

# First off, catch inbound automated backups.
:0
* ^Subject: DB backup, kyhm
| ~/bin/catch_backup ~/kyhm.com/backups/db



  The ~/bin/catch_backup script is as follows:

#!/bin/sh
if [ $1 !=  -a -d $1 ] ; then
cd $1
else
cd ~
fi
cat | uudecode



  Hope this is useful...

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356



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




Re: [PHP] phpUpLoad

2002-11-22 Thread Morgan Hughes
On Fri, 22 Nov 2002, Adam Williams wrote:

 You either need to make the directory 777 or change the ownership of the
 dir to apache or nobody (depending on which user httpd runs as)
   Adam

  ... or use a wrapper SUID to the user or group who owns the dir and have
  it wrap a back-end script that actually does the work.  I've used this
  effectively, and so long as the back-end script is properly written I
  believe it's a very secure method.

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356




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




Re: [PHP] writing to a file

2002-11-22 Thread Morgan Hughes
On Fri, 22 Nov 2002, Jason Wong wrote:
 On Friday 22 November 2002 16:34, gamin wrote:
  Hello,
  file as the data is being written, not when the file is closed
 I think you should try fclose() the file before you die!

  Or, if you need to force the data out to disk while writing, use
  fflush()...

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356




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




Re: [PHP] GD : Black background with imagecreatetruecolor

2002-11-21 Thread Morgan Hughes
On Thu, 21 Nov 2002, Arnaud wrote:

 Hi everyone,
 I'd like to use imagecreatetruecolor function in order to cut and paste
 JPG files on a white background. It seems not to work correctly.

  This one bit me when I started working with GD 2.x as well.  Simply draw
  a filled rectangle over your entire canvas in the color you want:

?
  $im=imagecreatetruecolor(50,50);
  $COULEUR_BLANC=imagecolorallocate($im,255,255,255);
  imagefilledrectangle($im,0,0,49,49,$COULEUR_BLANC);
  header (Content-type: image/png);
  ImagePNG($im);
  imagedestroy($im);
?

  The reason seems to be that when you create an indexed-color image
  (imagecreate()) gd sets all pixels to index 0, and when you allocate
  your first color, that's index 0.  Thus all background pixels magically
  become that color.

  When you use imagecreatetruecolor(), it sets all the pixels to black,
  and you have to explicitly draw them in to get them white.

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356




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




[PHP] Unusual HTTP header control

2002-11-16 Thread Morgan Hughes

  Hello list, I'm hoping someone can shed some light on a problem I'm
  having with the header() function...

  I'm building a script to spool MP3 files to Winamp/xmms using the HTTP
  protocol.  And it works fine, except I want to suppress the normal
  HTTP/1.1 200 OK header sent by PHP/Apache and instead send ICY 200
  OK, to fool the player into thinking it's listening to a ShoutCast
  server...

  Does anyone know how to do this?  The docs on header() don't mention it,
  nor do the user notes...  Any ideas?  Thanks!

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356




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




RE: [PHP] Unusual HTTP header control

2002-11-16 Thread Morgan Hughes
On Sun, 17 Nov 2002, Brendon G wrote:

 Not that I've ever used them but wouldn't Sockets be a good place to start?
 Cheers
 Brendon

  Possibly, but the rest of the script works well...  And I've got more
  experience feeding files back with PHP, and letting PHP do the heavy
  lifting for me... ^_^

-- 
   Morgan Hughes
   C programmer and highly caffeinated mammal.
   [EMAIL PROTECTED]
   ICQ: 79293356



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