Current location: Hot Scripts Forums » Programming Languages » PHP » email uploaded image?


email uploaded image?

Reply
  #1 (permalink)  
Old 11-10-09, 08:34 PM
braca86 braca86 is offline
Newbie Coder
 
Join Date: Oct 2009
Posts: 14
Thanks: 8
Thanked 0 Times in 0 Posts
email uploaded image?

ok, this is the code im using for uploading files on server... all i want is to send email as notificaction that file is successful uploaded and with link for the file or the file name.... any help?

PHP Code:

<?php
//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","1000");

//This function reads the extension of the file. It is used to determine if the file is an image by checking the extension.
function getExtension($str) {
$i strrpos($str,".");
if (!
$i) { return ""; }
$l strlen($str) - $i;
$ext substr($str,$i+1,$l);
return 
$ext;
}

//This variable is used as a flag. The value is initialized with 0 (meaning no error found) and it will be changed to 1 if an errro occures. If the error occures the file will not be uploaded.
$errors=0;
//checks if the form has been submitted
if(isset($_POST['Submit']))
{
//reads the name of the file the user submitted for uploading
$image=$_FILES['image']['name'];
//if it is not empty
if ($image)
{
//get the original name of the file from the clients machine
$filename stripslashes($_FILES['image']['name']);
//get the extension of the file in a lower case format
$extension getExtension($filename);
$extension strtolower($extension);
//if it is not a known extension, we will suppose it is an error and will not upload the file, otherwize we will do more tests
if (($extension != "jpg") && ($extension != "jpeg") && ($extension != "png") && ($extension != "gif"))
{
//print error message
echo '<h1>Unknown extension!</h1>';
$errors=1;
}
else
{
//get the size of the image in bytes
//$_FILES['image']['tmp_name'] is the temporary filename of the file in which the uploaded file was stored on the server
$size=filesize($_FILES['image']['tmp_name']);

//compare the size with the maxim size we defined and print error if bigger
if ($size MAX_SIZE*1024)
{
echo 
'<h1>You have exceeded the size limit!</h1>';
$errors=1;
}


//the new name will be containing the full path where will be stored (images folder)
$newname="http://www.hotscripts.com/forums/images/uploads/".$image_name;
//we verify if the image has been uploaded, and print error instead
$copied copy($_FILES['image']['tmp_name'], $newname);
if (!
$copied)
{
echo 
'<h1>Copy unsuccessfull!</h1>';
$errors=1;
}}}}

//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
echo 
"<h1>File Uploaded Successfully! Try again!</h1>";
}

?>

<!--next comes the form, you must set the enctype to "multipart/frm-data" and use an input type "file" -->
<form name="newad" method="post" enctype="multipart/form-data" action="">
<table>
<tr><td><input type="file" name="image"></td></tr>
<tr><td><input name="Submit" type="submit" value="Upload image"></td></tr>
</table>
</form>

Last edited by Nico; 11-11-09 at 10:39 AM.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #2 (permalink)  
Old 11-11-09, 08:40 AM
therocket954's Avatar
therocket954 therocket954 is offline
Community Liaison
 
Join Date: Jul 2007
Location: Michigan, USA
Posts: 334
Thanks: 2
Thanked 8 Times in 8 Posts
Try this.... Replace the bottom block of your PHP code with this: (Of course, you'll need to modify it with your correct email address and domain name.
PHP Code:

//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
    
$to "me@mydomain.com";
    
$subject "File upload";
    
$body "My file uploaded successfully... The link is: ";
    
$body .= "http://mydomain.com/" .$newname;
    
    
// Send the email
    
mail($to$subject$body"From: <me@mydomain.com>");
    
    
// Show message
    
echo "<h1>File Uploaded Successfully! Try again!</h1>";

__________________
--Eric Allison
Twitter: http://www.twitter.com/Eric_Allison
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to therocket954 For This Useful Post:
braca86 (11-11-09)
  #3 (permalink)  
Old 11-11-09, 09:40 AM
braca86 braca86 is offline
Newbie Coder
 
Join Date: Oct 2009
Posts: 14
Thanks: 8
Thanked 0 Times in 0 Posts
i did that and im getting error message

Quote:
Warning: copy(images/uploads/) [function.copy]: failed to open stream: Is a directory in /home/antline/public_html/email.php on line 53

and line 53 is

Quote:
$copied = copy($_FILES['image']['tmp_name'], $newname);
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #4 (permalink)  
Old 11-11-09, 10:41 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,074
Thanks: 11
Thanked 88 Times in 83 Posts
PHP Code:

$newname="http://www.hotscripts.com/forums/images/uploads/".$image_name
... should probably be:
PHP Code:

$newname="http://www.hotscripts.com/forums/images/uploads/".$image

Although, you should use move_uploaded_file instead of copy().
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to Nico For This Useful Post:
braca86 (11-11-09)
  #5 (permalink)  
Old 11-11-09, 11:13 AM
braca86 braca86 is offline
Newbie Coder
 
Join Date: Oct 2009
Posts: 14
Thanks: 8
Thanked 0 Times in 0 Posts
now working perfectly ok .....
just 1 more thing... i'w added inputbox for the customer to write his name
Quote:
<input type="text" name="firstname" id="firstname" />
how to send that along with the rest data in email???
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #6 (permalink)  
Old 11-12-09, 09:04 AM
therocket954's Avatar
therocket954 therocket954 is offline
Community Liaison
 
Join Date: Jul 2007
Location: Michigan, USA
Posts: 334
Thanks: 2
Thanked 8 Times in 8 Posts
This will work:

Change your top block of PHP to this:
PHP Code:

//define a maxim size for the uploaded images in Kb
define ("MAX_SIZE","1000");
// Get name from form
$firstname $_POST['firstname']; 
And then in your block of code that sends the email change to this:

PHP Code:

//If no errors registred, print the success message
if(isset($_POST['Submit']) && !$errors)
{
    
$to "me@mydomain.com";
    
$subject "File upload";
    
$body "My file uploaded successfully... The link is: " .$newname;
    
$body .= "\n"// just creates a new line
    
$body .= "Name: " .$firstname;
    
    
// Send the email
    
mail($to$subject$body"From: <me@mydomain.com>");
    
    
// Show message
    
echo "<h1>File Uploaded Successfully! Try again!</h1>";

__________________
--Eric Allison
Twitter: http://www.twitter.com/Eric_Allison
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to therocket954 For This Useful Post:
braca86 (11-13-09)
  #7 (permalink)  
Old 11-13-09, 03:52 AM
braca86 braca86 is offline
Newbie Coder
 
Join Date: Oct 2009
Posts: 14
Thanks: 8
Thanked 0 Times in 0 Posts
cool.... working... tnx all...
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #8 (permalink)  
Old 11-15-09, 11:42 PM
ContentSpooling ContentSpooling is offline
New Member
 
Join Date: Nov 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks therocket for the code. I also need this.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #9 (permalink)  
Old 11-29-09, 12:10 PM
braca86 braca86 is offline
Newbie Coder
 
Join Date: Oct 2009
Posts: 14
Thanks: 8
Thanked 0 Times in 0 Posts
???

how to send email to 2 or more reciptiens????
ive tried with

$to = "me@mydomain.com; me2@mydomain.com";
$subject = "File upload";
$body = "My file uploaded successfully... The link is: ";

and with

$to = "me@mydomain.com;
$to = "me2@mydomain.com";
$subject = "File upload";
$body = "My file uploaded successfully... The link is: ";

its not working... any help????
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
  #10 (permalink)  
Old 11-29-09, 12:41 PM
therocket954's Avatar
therocket954 therocket954 is offline
Community Liaison
 
Join Date: Jul 2007
Location: Michigan, USA
Posts: 334
Thanks: 2
Thanked 8 Times in 8 Posts
Close. Try this:

PHP Code:

$to "first@my-domain.com" ", ";
$to .= "second@my-domain.com" ", ";
$to .= "third@my-domain.com" ", ";
$to .= "last@my-domain.com"
__________________
--Eric Allison
Twitter: http://www.twitter.com/Eric_Allison
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiShare on FacebookShare on Stumble UponShare on Twitter
Reply With Quote
The Following User Says Thank You to therocket954 For This Useful Post:
braca86 (11-29-09)
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Freeze columns in a table Rita Negi Script Requests 1 09-01-09 09:23 AM
div css theighost CSS 11 09-14-08 03:30 AM
How to email an image created on fly??? nitro4file PHP 5 05-14-06 01:53 PM
need help with viewing uploaded image on webpage? mikewooten PHP 0 03-16-04 08:39 PM


All times are GMT -5. The time now is 05:01 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.