PHP Coding
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Codewalkers ForumsPHP RelatedPHP Coding

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Codewalkers Forums Sponsor:
  #1  
Old July 8th, 2009, 06:54 AM
gilbertsavier gilbertsavier is offline
Registered User
Codewalkers Newbie (0 - 499 posts)
 
Join Date: Jul 2009
Posts: 9 gilbertsavier User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 35 m
Reputation Power: 0
php5 - Upload PHP file code

Hi,
I need a code that lets my customers upload a image file from their computer and then that file does 2 things

1. gets uploaded to upload folder on my server
2. a copy of that file gets e-mailed to me

this is what I have so far, any improvements/additions on this code would really be appreciated...

1.//GET IMAGE INFO
2.
3. $dir = 'images/';
4. $file_name = $_FILES['file']['name'];
5. $file_tmp = $_FILES['file']['tmp_name'];
6.
7. //CHECK FOR UPLOADED FILE
8. if(is_uploaded_file($file_tmp)){
9. //MOVE TO DIR
10. move_uploaded_file($file_tmp, $dir.$file_name);
11. }


---------------
Thanks & regards
Lokananth
Live chat By miOOt

Reply With Quote
  #2  
Old July 8th, 2009, 07:27 AM
DavidMR's Avatar
DavidMR DavidMR is offline
Contributing User
Codewalkers Beginner (1000 - 1499 posts)
 
Join Date: Apr 2007
Location: Galway
Posts: 1,025 DavidMR User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 Weeks 5 Days 12 h 53 m 12 sec
Reputation Power: 4
HTML

Code:
<html>
<body>

<form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file" />
<br />
<input type="submit" name="submit" value="Submit" />
</form>

</body>
</html> 


PHP

PHP Code:
<?php
if ((($_FILES["file"]["type"] == "image/gif")
|| (
$_FILES["file"]["type"] == "image/jpeg")
|| (
$_FILES["file"]["type"] == "image/pjpeg"))
&& (
$_FILES["file"]["size"] < 20000))
  {
  if (
$_FILES["file"]["error"] > 0)
    {
    echo 
"Return Code: " $_FILES["file"]["error"] . "<br />";
    }
  else
    {
    echo 
"Upload: " $_FILES["file"]["name"] . "<br />";
    echo 
"Type: " $_FILES["file"]["type"] . "<br />";
    echo 
"Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
    echo 
"Temp file: " $_FILES["file"]["tmp_name"] . "<br />";

    if (
file_exists("upload/" $_FILES["file"]["name"]))
      {
      echo 
$_FILES["file"]["name"] . " already exists. ";
      }
    else
      {
      
move_uploaded_file($_FILES["file"]["tmp_name"],
      
"upload/" $_FILES["file"]["name"]);
      echo 
"Stored in: " "upload/" $_FILES["file"]["name"];
      }
    }
  }
else
  {
  echo 
"Invalid file";
  }
?>


emailing:

PHP Code:
<?php
//define the receiver of the email
$to 'youraddress@example.com';
//define the subject of the email
$subject 'Test email';
//define the message to be sent. Each line should be separated with \n
$message "Hello World!\n\nThis is my first mail.";
//define the headers we want passed. Note that they are separated with \r\n
$headers "From: webmaster@example.com\r\nReply-To: webmaster@example.com";
//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";
?>
__________________
When I die, I want to go peacefully like my Grandfather did, in his sleep -- not screaming, like the passengers in his car.

Reply With Quote
Reply

Viewing: Codewalkers ForumsPHP RelatedPHP Coding > php5 - Upload PHP file code


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump




 Free IT White Papers!
 
How to Present Effectively Online
This white paper offers practical and actionable advice on the key steps that any presenter should consider as they plan and execute a Webinar or online meeting.

Request Your Free Technology Downloads!
 
Open Source Security Myths
Open Source Software (OSS) is computer software whose source code is available to the general public with relaxed or non-existent intellectual property restrictions (or arrangement such as the public domain), and is usually developed with the input of many contributors.

Request Your Free Technology Downloads!
 
Power and Cooling Capacity Management for Data Centers
This paper describes the principles for achieving power and cooling capacity management.

Request Your Free Technology Downloads!
 
Scalable, Fault-Tolerant NAS for Oracle - The Next Generation
For several years NAS has been evolving as a storage alternative for Oracle databases, and for good reason: NAS is quite often the simplest, most cost-effective storage approach for Oracle. Learn about the benefits that HP's approach to scalable NAS brings to Oracle environments in this comprehensive white paper.

Request Your Free Technology Downloads!
 
Understanding Web Application Security Challenges
This white paper discusses many common threats and preventive measures for Web application security, and explains what you can do to help protect your organization.

Request Your Free Technology Downloads!
 

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 




© 2003-2009 by Developer Shed. All rights reserved. DS Cluster 4 Hosted by Hostway
Stay green...Green IT