faqts : Computers : Programming : Languages : PHP

+ Search
Add Entry AlertManage Folder Edit Entry Add page to http://del.icio.us/
Did You Find This Entry Useful?

9 of 14 people (64%) answered Yes
Recently 6 of 10 people (60%) answered Yes


How to do attachment if I want to use a file as background?

Feb 22nd, 2008 20:17
dman, Dimitur Kirov, Selina Chong, http://www.ttnr.org

PHP has the posibility to recognize the MIME type of the uploaded file. 
For your case you need such MIME types 
like 'image/gif', 'image/jpeg', 'image/png', 'image/tiff' etc. , so 
ones knowing the MIME type you check if it begins with the 
string 'image'. A simple way of doing that is:
///file upload.php - > form with upload input tag/////
///ENCTYPE="multipart/form-data" -this is neccessary!
<form method="post" name="form1" action="check.php" 
  <INPUT name="file1" type="file" onchange="document.form1.submit();">
///file check.php if image save it to the server 
///main directory and set it as a background.
$type=$file1_type;   //gets the MIME type
if(ereg ("^image", $type)) {$g=0;}
else $g=1;
if (!$g) {
    $img_s="/" . $file1_name;
if (file_exists($img_s))
<body <?php if(isset($img_s)) printf(" background=\"%s\" ",$img_s); ?> >
 if ($g) {
     printf("alert('This is not a valid image type!');\nwindow.close