| | |
Sending attached files in php
Please support our PHP advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2007
Posts: 41
Reputation:
Solved Threads: 1
Could you please help realize the procedure of sending attached files in php. If it is possible, please, provide me with ready code examples. Thanks in advance!
www.onestopmarketing.com - affordable SEO tools and services.
There are multiple resources online which deal with this issue, a quick search comes up with exactly what you are looking for, please research and dont ask other people to do all the work.
Post an example of what you have if it isnt working and we can assist you.
Post an example of what you have if it isnt working and we can assist you.
AJAX is not a programming language, scripting language or any other sort of language.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
It is acheived by using JavaScript http functions.
So, AJAX = JavaScript.
phpmailer is an amazing class and there are ready examples in the download, just do a search for phpmailer download.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
see this url:
http://www.hollowearth.co.uk/tech/ph...ttachments.php
http://www.hollowearth.co.uk/tech/ph...ttachments.php
Be intelligent, But Don't try to cheat.. Be innocent But Don't get cheated..
See if this helps. To use this script, you need to create a folder named uploads where the uploaded files would be stored.
This bit of code moves the uploaded file from a temporary directory into the uploads directory:
The MIME types included here are: .gif, .pjpeg and .jpeg but you may like to add more file formats.
This first line of the code defines the maximum file size: You can edit the size to suit your needs.
PHP Syntax (Toggle Plain Text)
<?php $maxsize=28480; // Set the maximum upload size in bytes if (!$_POST['submit']) { //print_r($_FILES); $error=" "; // This will cause the rest of the process to be skipped //and the upload form displays } if (!is_uploaded_file($_FILES['upload_file']['tmp_name']) AND !isset($error)) { $error = "<b>You must upload a file!</b><br /><br />"; unlink($_FILES['upload_file']['tmp_name']); } if ($_FILES['upload_file']['size'] > $maxsize AND !isset($error)) { $error = "<b>Error, file must be less than $maxsize bytes.</b><br /><br />"; unlink($_FILES['upload_file']['tmp_name']); } if($_FILES['upload_file']['type'] != "image/gif" AND $_FILES['upload_file']['type'] != "image/pjpeg" AND $_FILES['upload_file']['type'] !="image/jpeg" AND !isset($error)) { $error = "<b>You may only upload .gif or .jpeg files.<b><br /><br />"; unlink($_FILES['upload_file']['tmp_name']); } if (!isset($error)) { move_uploaded_file($_FILES['upload_file']['tmp_name'], "uploads/".$_FILES['upload_file']['name']); print "Thank you for your upload."; exit; } else { echo ("$error"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP File Upload Script</title> </head> <body> <form action="<?php echo(htmlspecialchars($_SERVER['PHP_SELF']))?>" method="post" enctype="multipart/form-data"> Choose a file to upload:<br /> <input type="file" name="upload_file" size="50" /> <br /> <input type="submit" name="submit" value="Submit" /> <input type="reset" name="Reset" value="Reset" /> </form> </body> </html>
This bit of code moves the uploaded file from a temporary directory into the uploads directory:
PHP Syntax (Toggle Plain Text)
move_uploaded_file($_FILES['upload_file']['tmp_name'], "uploads/".$_FILES['upload_file']['name']);
The MIME types included here are: .gif, .pjpeg and .jpeg but you may like to add more file formats.
This first line of the code defines the maximum file size:
PHP Syntax (Toggle Plain Text)
$maxsize=28480; // Set the maximum upload size in bytes
•
•
Join Date: Oct 2008
Posts: 5
Reputation:
Solved Threads: 0
•
•
•
•
See if this helps. To use this script, you need to create a folder named uploads where the uploaded files would be stored.
PHP Syntax (Toggle Plain Text)
<?php $maxsize=28480; // Set the maximum upload size in bytes if (!$_POST['submit']) { //print_r($_FILES); $error=" "; // This will cause the rest of the process to be skipped //and the upload form displays } if (!is_uploaded_file($_FILES['upload_file']['tmp_name']) AND !isset($error)) { $error = "<b>You must upload a file!</b><br /><br />"; unlink($_FILES['upload_file']['tmp_name']); } if ($_FILES['upload_file']['size'] > $maxsize AND !isset($error)) { $error = "<b>Error, file must be less than $maxsize bytes.</b><br /><br />"; unlink($_FILES['upload_file']['tmp_name']); } if($_FILES['upload_file']['type'] != "image/gif" AND $_FILES['upload_file']['type'] != "image/pjpeg" AND $_FILES['upload_file']['type'] !="image/jpeg" AND !isset($error)) { $error = "<b>You may only upload .gif or .jpeg files.<b><br /><br />"; unlink($_FILES['upload_file']['tmp_name']); } if (!isset($error)) { move_uploaded_file($_FILES['upload_file']['tmp_name'], "uploads/".$_FILES['upload_file']['name']); print "Thank you for your upload."; exit; } else { echo ("$error"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP File Upload Script</title> </head> <body> <form action="<?php echo(htmlspecialchars($_SERVER['PHP_SELF']))?>" method="post" enctype="multipart/form-data"> Choose a file to upload:<br /> <input type="file" name="upload_file" size="50" /> <br /> <input type="submit" name="submit" value="Submit" /> <input type="reset" name="Reset" value="Reset" /> </form> </body> </html>
This bit of code moves the uploaded file from a temporary directory into the uploads directory:
PHP Syntax (Toggle Plain Text)
move_uploaded_file($_FILES['upload_file']['tmp_name'], "uploads/".$_FILES['upload_file']['name']);
The MIME types included here are: .gif, .pjpeg and .jpeg but you may like to add more file formats.
This first line of the code defines the maximum file size:You can edit the size to suit your needs.PHP Syntax (Toggle Plain Text)
$maxsize=28480; // Set the maximum upload size in bytes
hi.. does this code displays the uploaded picture? tnx..
•
•
Join Date: Jan 2007
Posts: 41
Reputation:
Solved Threads: 1
Thanks, mexabet, your post seems to be the most helpful for me!
www.onestopmarketing.com - affordable SEO tools and services.
•
•
•
•
See if this helps. To use this script, you need to create a folder named uploads where the uploaded files would be stored.
PHP Syntax (Toggle Plain Text)
<?php $maxsize=28480; // Set the maximum upload size in bytes if (!$_POST['submit']) { //print_r($_FILES); $error=" "; // This will cause the rest of the process to be skipped //and the upload form displays } if (!is_uploaded_file($_FILES['upload_file']['tmp_name']) AND !isset($error)) { $error = "<b>You must upload a file!</b><br /><br />"; unlink($_FILES['upload_file']['tmp_name']); } if ($_FILES['upload_file']['size'] > $maxsize AND !isset($error)) { $error = "<b>Error, file must be less than $maxsize bytes.</b><br /><br />"; unlink($_FILES['upload_file']['tmp_name']); } if($_FILES['upload_file']['type'] != "image/gif" AND $_FILES['upload_file']['type'] != "image/pjpeg" AND $_FILES['upload_file']['type'] !="image/jpeg" AND !isset($error)) { $error = "<b>You may only upload .gif or .jpeg files.<b><br /><br />"; unlink($_FILES['upload_file']['tmp_name']); } if (!isset($error)) { move_uploaded_file($_FILES['upload_file']['tmp_name'], "uploads/".$_FILES['upload_file']['name']); print "Thank you for your upload."; exit; } else { echo ("$error"); } ?> <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>PHP File Upload Script</title> </head> <body> <form action="<?php echo(htmlspecialchars($_SERVER['PHP_SELF']))?>" method="post" enctype="multipart/form-data"> Choose a file to upload:<br /> <input type="file" name="upload_file" size="50" /> <br /> <input type="submit" name="submit" value="Submit" /> <input type="reset" name="Reset" value="Reset" /> </form> </body> </html>
This bit of code moves the uploaded file from a temporary directory into the uploads directory:
PHP Syntax (Toggle Plain Text)
move_uploaded_file($_FILES['upload_file']['tmp_name'], "uploads/".$_FILES['upload_file']['name']);
The MIME types included here are: .gif, .pjpeg and .jpeg but you may like to add more file formats.
This first line of the code defines the maximum file size:You can edit the size to suit your needs.PHP Syntax (Toggle Plain Text)
$maxsize=28480; // Set the maximum upload size in bytes
•
•
•
•
Thanks, mexabet, your post seems to be the most helpful for me!
php Syntax (Toggle Plain Text)
<?php function returnFileName($file) { $dot = strrpos($file, '.'); if($dot === false)//file has no dot { return false; } $fileinfo = array(); $fileinfo['base'] = substr($file, 0, $dot); $fileinfo['ext'] = strtolower(substr($file, $dot + 1)); return $fileinfo; } $allowedext = array("jpg", "gif"); $filearray = returnFileName(basename($_FILES['upload_file']['name'])); if($filearray == false || !isset($filearray['ext']) || !in_array($filearray['ext'], $allowedext)) { $error .= "invalid file type"; } ?>
Last edited by R0bb0b; Oct 13th, 2008 at 8:33 am.
“Be who you are and say what you feel because those who mind don't matter and those who matter don't mind.” - Dr. Seuss
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
-- The documentation is inevitable, you may get away with it for a little while but eventually you too will have to do the deed.
R0bb0b,
No offenses taken! Instead, we are working together to get a good working script for our fellow community member.
No offenses taken! Instead, we are working together to get a good working script for our fellow community member.
![]() |
Other Threads in the PHP Forum
- Previous Thread: mysql_real_escape_string ?
- Next Thread: Drupal 404 Error Page Not Working
| Thread Tools | Search this Thread |
ajax apache api array beginner binary body broken cakephp checkbox class cms code cron curl database date date/time display dynamic echo email error file files folder form forms function functions gc_maxlifetime global google host href htaccess html image include insert integration ip java javascript joomla limit link list login loop mail memmory menu mlm msqli_multi_query multiple mycodeisbad mysql navigation oop parameter parsing paypal pdf php problem query radio random recourse recursion regex registrationform remote script search seo server sessions sms soap source space sql static syntax system table tutorial update upload url validator variable video web webdesign wordpress xml youtube






