php-general Digest 26 Jun 2010 21:36:56 -0000 Issue 6817

2010-06-26 Thread php-general-digest-help

php-general Digest 26 Jun 2010 21:36:56 - Issue 6817

Topics (messages 306452 through 306455):

Re: Attachment to email from form.
306452 by: Gary
306453 by: Gary
306454 by: Gary

Re: Character Encoding for em-dash
306455 by: tedd

Administrivia:

To subscribe to the digest, e-mail:
php-general-digest-subscr...@lists.php.net

To unsubscribe from the digest, e-mail:
php-general-digest-unsubscr...@lists.php.net

To post to the list, e-mail:
php-gene...@lists.php.net


--
---BeginMessage---

Ashley Sheridan a...@ashleysheridan.co.uk wrote in message 
news:1277474393.2787.82.ca...@localhost...
 On Fri, 2010-06-25 at 09:51 -0400, Gary wrote:

 I am trying to have an attachment to an email from a form.  Email is 
 working
 fine, am unable to get attachment. The attachment will be a word.doc.

 I am getting error message

 Warning: file_get_contents(attachment.zip) [function.file-get-contents]:
 failed to open stream: No such file or directory in
 /home/oneonel1/public_html/emailreminderresult.inc.php on line 24
 Mail failed

 Line 24 reads:

 $attachment =
 chunk_split(base64_encode(file_get_contents('attachment.zip')));

 here is the all of the code that I have removed the email addresses  
 such.

 Can someone point me in the right direction?

 Thank you

 Gary

 ?php
 $fname=stripslashes($_POST['fname']);
 $lname=stripslashes($_POST['lname']);
 $email=stripslashes($_POST['email']);
 $comments=stripslashes($_POST['comments']);
 $ip= $_SERVER['REMOTE_ADDR'];
 $attachment = $_POST['attachment'];

 $attachment = $_FILES['attachment']['name'];
 $attachment_type = $_FILES['attachment']['type'];
 $attachment_size = $_FILES['attachment']['size'];

 //create a boundary string. It must be unique
 //so we use the MD5 algorithm to generate a random hash
 $random_hash = md5(date('r', time()));
 //define the headers we want passed. Note that they are separated with 
 \r\n
 $headers = From: myemail\r\nReply-To: myemail.com;
 //add boundary string and mime type specification
 $headers .= \r\nContent-Type: multipart/mixed;
 boundary=\PHP-mixed-.$random_hash.\;
 //read the atachment file contents into a string,
 //encode it with MIME base64,
 //and split it into smaller chunks
 $attachment =
 chunk_split(base64_encode(file_get_contents('attachment.zip'))); //line 
 24
 //define the body of the message.
 ob_start();

 //Turn on output buffering

 //--PHP-mixed-
  echo $random_hash;
 //Content-Type: multipart/alternative; boundary=PHP-alt-
  echo $random_hash;

 //--PHP-alt-
  echo $random_hash;

 /* Content-Type: text/plain; charset=iso-8859-1
 Content-Transfer-Encoding: 7bit */



 //--PHP-alt-
  echo $random_hash;
 /* Content-Type: text/html; charset=iso-8859-1
 Content-Transfer-Encoding: 7bit */


 //--PHP-alt-

  echo $random_hash;

 //--PHP-mixed-


 echo $random_hash;

 /* Content-Type: application/zip; name=attachment.zip
 Content-Transfer-Encoding: base64
 Content-Disposition: attachment  */

  echo $attachment;
 //--PHP-mixed-

  echo $random_hash;


 //copy current buffer contents into $message variable and delete current
 output buffer
 $message = ob_get_clean();
 //send the email
 $mail_sent = @mail( $to, $subject, $message, $headers );
 //if the message is sent successfully print Mail sent. Otherwise print
 Mail failed
 echo $mail_sent ? Mail sent : Mail failed;



 echo Thank you for contacting b888!/bbr /br /;
 echo You have submitted the following information:br /br /;
 echo Name: $fname  $lnamebr /;
 echo E-Mail Address: $emailbr /;
 echo Your comments or request: $commentsbr /br /br /;




  echo We have also sent you an e-mail to $email with the submitted
 information as well as our contact information for your convienience. br
 /br /
  Thank you for the opportunity to serve you!;


 /*This is the email message to submitter*/
 $contact=888\n 888\n 888;
 $from_d=$email;
 $to_d=$email;
 $subject_d='Thank you from 888';
 $msg_d=Thank you $fname for your submission, find our contact 
 information
 listed for your convenience.\n\n
 .$contact\n\n
 . You have submitted the following information\n\n
 . Name:  $fname  $lname \n
 . E-Mail Address: $email\n
 . Comments: $comments\n
 ;
 mail($to_d, $subject_d, $msg_d, 'From:' . $from_d);


 /*this is to form owner, */
 $from=$email;
 $to=myemail;
 $subject=Submission from 888;
 $msg= This is a submission from 888com. \n\n
 . Clients Name: $fname . $lname \n
 . Email Address: $email\n
 . Comments: $comments\n
 ;


 mail($to, $subject, $msg, 'From:' .$from);

 ?



 __ Information from ESET Smart Security, version of virus 
 signature database 5228 (20100625) __

 The message was checked by ESET Smart Security.

 http://www.eset.com





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



 Your script can't find the attachment.zip file. As you're using a
 relative path to 

Re: [PHP] Using fopen or SQL to check image

2010-06-26 Thread Karl Cifius
Thanks Ashley and Peter for your suggestions, I've definitely learned  
some new stuff here.


Best,
Karl


On 25 jun 2010, at 21.07, Peter Lind peter.e.l...@gmail.com wrote:

On 25 June 2010 21:02, Ashley Sheridan a...@ashleysheridan.co.uk  
wrote:


On Fri, 2010-06-25 at 21:01 +0200, Peter Lind wrote:

On 25 June 2010 20:59, Ashley Sheridan a...@ashleysheridan.co.uk  
wrote:


On Fri, 2010-06-25 at 20:57 +0200, Peter Lind wrote:

On 25 June 2010 19:35, Ashley Sheridan a...@ashleysheridan.co.uk  
wrote:

On Fri, 2010-06-25 at 19:31 +0200, Karl Cifius wrote:


Hi,

I'm making a Facebook application that can generate images to  
user's
albums. To publish a story a thumbnail of this image is stored  
on my
server. Since this server currently is very limited I want to be  
able

to clean these thumbnails pretty often.

To not get broken links in older facebook stories the address to  
the
thumbnail is a php script that checks if the thumbnail is  
available

and returns it, or otherwise returns a default thumbnail.

I have solved this using the following code:

$tImage = $_GET['i'];
$tURL   = upload/$tImage.jpg;
if(!($fp=fopen($tURL,rb))){
   header(Location: thumb.jpg);
}else{
   header(Location: upload/$tImage.jpg);
   fclose($fp);
}

My question is if it would be better to have a mysql database with
information about the thumbnail and check if the image is there,
instead of checking if the image file can be loaded? What is the  
most

optimized approach if I start to gain traffic?


Thanks,

/Karl




I think checking for the existence of a file is probably going to  
be the
quicker approach. Unless you have a server with loads of RAM and  
your DB
is very small, it's unlikely your DB will exist entirely in  
memory, so
you will at some point have to access the files that the DB uses,  
even

though this is done by the server automatically.

On another note, I would try to sanitise that $_GET variable a  
bit, as
it could lead to issues down the line later. Maybe limit the  
string to

patterns you expect for an image URL.

Thanks,
Ash
http://www.ashleysheridan.co.uk



Might be quicker to do with a .htaccess file - you can avoid  
loading php at all.


Regards
Peter



PHP can do things that .htaccess can't, like verify a specific ID  
has access to an image, etc.




I must've missed the part in the code where the ID was checked ...
Nope, still can't find it.

Regards
Peter


--
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype

It wasn't in the example, but generally I've found the only reason  
someone ever thinks of doing something like this rather than  
directly link to the image is for some sort of validation reason. I  
assumed it was a slimmed-down code sample that only showed us what  
we needed.




Ahh, I see. I assumed the OP would have told us if that was the case -
I prefer answering the stated questions instead of guessing at what
they are.

Regards
Peter

--
hype
WWW: http://plphp.dk / http://plind.dk
LinkedIn: http://www.linkedin.com/in/plind
BeWelcome/Couchsurfing: Fake51
Twitter: http://twitter.com/kafe15
/hype


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



Re: [PHP] Attachment to email from form.

2010-06-26 Thread Gary

Ashley Sheridan a...@ashleysheridan.co.uk wrote in message 
news:1277474393.2787.82.ca...@localhost...
 On Fri, 2010-06-25 at 09:51 -0400, Gary wrote:

 I am trying to have an attachment to an email from a form.  Email is 
 working
 fine, am unable to get attachment. The attachment will be a word.doc.

 I am getting error message

 Warning: file_get_contents(attachment.zip) [function.file-get-contents]:
 failed to open stream: No such file or directory in
 /home/oneonel1/public_html/emailreminderresult.inc.php on line 24
 Mail failed

 Line 24 reads:

 $attachment =
 chunk_split(base64_encode(file_get_contents('attachment.zip')));

 here is the all of the code that I have removed the email addresses  
 such.

 Can someone point me in the right direction?

 Thank you

 Gary

 ?php
 $fname=stripslashes($_POST['fname']);
 $lname=stripslashes($_POST['lname']);
 $email=stripslashes($_POST['email']);
 $comments=stripslashes($_POST['comments']);
 $ip= $_SERVER['REMOTE_ADDR'];
 $attachment = $_POST['attachment'];

 $attachment = $_FILES['attachment']['name'];
 $attachment_type = $_FILES['attachment']['type'];
 $attachment_size = $_FILES['attachment']['size'];

 //create a boundary string. It must be unique
 //so we use the MD5 algorithm to generate a random hash
 $random_hash = md5(date('r', time()));
 //define the headers we want passed. Note that they are separated with 
 \r\n
 $headers = From: myemail\r\nReply-To: myemail.com;
 //add boundary string and mime type specification
 $headers .= \r\nContent-Type: multipart/mixed;
 boundary=\PHP-mixed-.$random_hash.\;
 //read the atachment file contents into a string,
 //encode it with MIME base64,
 //and split it into smaller chunks
 $attachment =
 chunk_split(base64_encode(file_get_contents('attachment.zip'))); //line 
 24
 //define the body of the message.
 ob_start();

 //Turn on output buffering

 //--PHP-mixed-
  echo $random_hash;
 //Content-Type: multipart/alternative; boundary=PHP-alt-
  echo $random_hash;

 //--PHP-alt-
  echo $random_hash;

 /* Content-Type: text/plain; charset=iso-8859-1
 Content-Transfer-Encoding: 7bit */



 //--PHP-alt-
  echo $random_hash;
 /* Content-Type: text/html; charset=iso-8859-1
 Content-Transfer-Encoding: 7bit */


 //--PHP-alt-

  echo $random_hash;

 //--PHP-mixed-


 echo $random_hash;

 /* Content-Type: application/zip; name=attachment.zip
 Content-Transfer-Encoding: base64
 Content-Disposition: attachment  */

  echo $attachment;
 //--PHP-mixed-

  echo $random_hash;


 //copy current buffer contents into $message variable and delete current
 output buffer
 $message = ob_get_clean();
 //send the email
 $mail_sent = @mail( $to, $subject, $message, $headers );
 //if the message is sent successfully print Mail sent. Otherwise print
 Mail failed
 echo $mail_sent ? Mail sent : Mail failed;



 echo Thank you for contacting b888!/bbr /br /;
 echo You have submitted the following information:br /br /;
 echo Name: $fname  $lnamebr /;
 echo E-Mail Address: $emailbr /;
 echo Your comments or request: $commentsbr /br /br /;




  echo We have also sent you an e-mail to $email with the submitted
 information as well as our contact information for your convienience. br
 /br /
  Thank you for the opportunity to serve you!;


 /*This is the email message to submitter*/
 $contact=888\n 888\n 888;
 $from_d=$email;
 $to_d=$email;
 $subject_d='Thank you from 888';
 $msg_d=Thank you $fname for your submission, find our contact 
 information
 listed for your convenience.\n\n
 .$contact\n\n
 . You have submitted the following information\n\n
 . Name:  $fname  $lname \n
 . E-Mail Address: $email\n
 . Comments: $comments\n
 ;
 mail($to_d, $subject_d, $msg_d, 'From:' . $from_d);


 /*this is to form owner, */
 $from=$email;
 $to=myemail;
 $subject=Submission from 888;
 $msg= This is a submission from 888com. \n\n
 . Clients Name: $fname . $lname \n
 . Email Address: $email\n
 . Comments: $comments\n
 ;


 mail($to, $subject, $msg, 'From:' .$from);

 ?



 __ Information from ESET Smart Security, version of virus 
 signature database 5228 (20100625) __

 The message was checked by ESET Smart Security.

 http://www.eset.com





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



 Your script can't find the attachment.zip file. As you're using a
 relative path to it, it should be in the same directory as your php
 script, or somewhere directly in the path environment variable.

 Also, make sure that the file has read properties set to allow Apache to
 read it.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk

 Ashley

Thank you for your response and I'm sorry for the delay.  I'm not sure I 
understand your answer. I tried changing the 'attahcment.zip' to 
$attachment, even creating a temp folder with reference to the path, however 
it does not seem to work.

Perhaps you could explain a little further?

Again, thank you for your response.

Gary 



__ Information from 

Re: [PHP] Attachment to email from form.

2010-06-26 Thread Gary

Bastien Koert phps...@gmail.com wrote in message 
news:aanlktilfxsbs83zaaa6ix32yhurqdg9azd6twq_hn...@mail.gmail.com...
On Fri, Jun 25, 2010 at 9:59 AM, Ashley Sheridan
a...@ashleysheridan.co.uk wrote:
 On Fri, 2010-06-25 at 09:51 -0400, Gary wrote:

 I am trying to have an attachment to an email from a form. Email is 
 working
 fine, am unable to get attachment. The attachment will be a word.doc.

 I am getting error message

 Warning: file_get_contents(attachment.zip) [function.file-get-contents]:
 failed to open stream: No such file or directory in
 /home/oneonel1/public_html/emailreminderresult.inc.php on line 24
 Mail failed

 Line 24 reads:

 $attachment =
 chunk_split(base64_encode(file_get_contents('attachment.zip')));

 here is the all of the code that I have removed the email addresses  
 such.

 Can someone point me in the right direction?

 Thank you

 Gary

 ?php
 $fname=stripslashes($_POST['fname']);
 $lname=stripslashes($_POST['lname']);
 $email=stripslashes($_POST['email']);
 $comments=stripslashes($_POST['comments']);
 $ip= $_SERVER['REMOTE_ADDR'];
 $attachment = $_POST['attachment'];

 $attachment = $_FILES['attachment']['name'];
 $attachment_type = $_FILES['attachment']['type'];
 $attachment_size = $_FILES['attachment']['size'];

 //create a boundary string. It must be unique
 //so we use the MD5 algorithm to generate a random hash
 $random_hash = md5(date('r', time()));
 //define the headers we want passed. Note that they are separated with 
 \r\n
 $headers = From: myemail\r\nReply-To: myemail.com;
 //add boundary string and mime type specification
 $headers .= \r\nContent-Type: multipart/mixed;
 boundary=\PHP-mixed-.$random_hash.\;
 //read the atachment file contents into a string,
 //encode it with MIME base64,
 //and split it into smaller chunks
 $attachment =
 chunk_split(base64_encode(file_get_contents('attachment.zip'))); //line 
 24
 //define the body of the message.
 ob_start();

 //Turn on output buffering

 //--PHP-mixed-
 echo $random_hash;
 //Content-Type: multipart/alternative; boundary=PHP-alt-
 echo $random_hash;

 //--PHP-alt-
 echo $random_hash;

 /* Content-Type: text/plain; charset=iso-8859-1
 Content-Transfer-Encoding: 7bit */



 //--PHP-alt-
 echo $random_hash;
 /* Content-Type: text/html; charset=iso-8859-1
 Content-Transfer-Encoding: 7bit */


 //--PHP-alt-

 echo $random_hash;

 //--PHP-mixed-


 echo $random_hash;

 /* Content-Type: application/zip; name=attachment.zip
 Content-Transfer-Encoding: base64
 Content-Disposition: attachment */

 echo $attachment;
 //--PHP-mixed-

 echo $random_hash;


 //copy current buffer contents into $message variable and delete current
 output buffer
 $message = ob_get_clean();
 //send the email
 $mail_sent = @mail( $to, $subject, $message, $headers );
 //if the message is sent successfully print Mail sent. Otherwise print
 Mail failed
 echo $mail_sent ? Mail sent : Mail failed;



 echo Thank you for contacting b888!/bbr /br /;
 echo You have submitted the following information:br /br /;
 echo Name: $fname $lnamebr /;
 echo E-Mail Address: $emailbr /;
 echo Your comments or request: $commentsbr /br /br /;




 echo We have also sent you an e-mail to $email with the submitted
 information as well as our contact information for your convienience. br
 /br /
 Thank you for the opportunity to serve you!;


 /*This is the email message to submitter*/
 $contact=888\n 888\n 888;
 $from_d=$email;
 $to_d=$email;
 $subject_d='Thank you from 888';
 $msg_d=Thank you $fname for your submission, find our contact 
 information
 listed for your convenience.\n\n
 .$contact\n\n
 . You have submitted the following information\n\n
 . Name: $fname $lname \n
 . E-Mail Address: $email\n
 . Comments: $comments\n
 ;
 mail($to_d, $subject_d, $msg_d, 'From:' . $from_d);


 /*this is to form owner, */
 $from=$email;
 $to=myemail;
 $subject=Submission from 888;
 $msg= This is a submission from 888com. \n\n
 . Clients Name: $fname . $lname \n
 . Email Address: $email\n
 . Comments: $comments\n
 ;


 mail($to, $subject, $msg, 'From:' .$from);

 ?



 __ Information from ESET Smart Security, version of virus 
 signature database 5228 (20100625) __

 The message was checked by ESET Smart Security.

 http://www.eset.com





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



 Your script can't find the attachment.zip file. As you're using a
 relative path to it, it should be in the same directory as your php
 script, or somewhere directly in the path environment variable.

 Also, make sure that the file has read properties set to allow Apache to
 read it.

 Thanks,
 Ash
 http://www.ashleysheridan.co.uk




Consider using something like phpmailer to handle the emails. Makes
attaching things really simple.

http://phpmailer.worxware.com/

-- 

Bastien

Cat, the other other white meat



Bastien

How could anyone not love your advice when you seem to enjoy cats so much! 
I did download the