![]() |
please help me with simple php
can someone help me add file types to my upload script please?
current it checks for jpeg and errors if it's not that one type: if ($type == "image/jpeg"){ i want to add supported file types so i've changed it to: if ($type == "image/jpeg") || ($type == "image/jpg") || ($type == "image/gif") || ($type == "image/psd") || ($type == "image/tiff") || ($type == "image/bmp") { but it's not happy... |
That should work, but it depends on what exactly is stored in $type variable.
|
PHP Code:
|
Quote:
|
$type = $_FILES['filename']['type'];
|
Quote:
|
thanks for your help!
here's the page it's on and the error: http://www.cheaptrace.com/contact.html Parse error: parse error, unexpected T_BOOLEAN_OR in /home/httpd/cheaptrace.com/html/sendmail.php on line 58 here's the whole script: <?php session_start(); if ($_POST["vercode"] != $_SESSION["vercode"] OR $_SESSION["vercode"]=='') { echo '<strong>Incorrect verification code.</strong><br>'; die; } else { if ($_SERVER['REQUEST_METHOD']=="POST"){ $sendername = $_POST['name']; $from = $_POST['mail']; $senderphone = $_POST['phone']; $sendercountry = $_POST['country']; $filename = basename($_FILES['filename']['name']); $ext = substr($filename, strrpos($filename, '.') + 1); $notes = $_POST['remarks']; $to="[email protected]"; $subject="Cheap Trace"; /*$from = stripslashes($_POST['fromname'])."<".stripslashes($_POST['fromemail']).">";*/ $mime_boundary="==Multipart_Boundary_x".md5(mt_ran d())."x"; $tmp_name = $_FILES['filename']['tmp_name']; $type = $_FILES['filename']['type']; $name = $_FILES['filename']['name']; $size = $_FILES['filename']['size']; $message = "Filename: $name\n"; $message .="type: $type\n"; $message .="size: $size\n\n"; if (file_exists($tmp_name)){ if(is_uploaded_file($tmp_name)){ $file = fopen($tmp_name,'rb'); $data = fread($file,filesize($tmp_name)); fclose($file); $data = chunk_split(base64_encode($data)); } $message .= "Name: "."$sendername\n"; $message .= "Country: "."$sendercountry\n"; $message .= "EMail Address: "."$from\n"; $message .= "Telephone: "."$senderphone\n\n"; $message .= "Remarks: "."$notes\n\n"; $headers = "From: $from\r\n" . "MIME-Version: 1.0\r\n" . "Content-Type: multipart/mixed;\r\n" . " boundary=\"{$mime_boundary}\""; $message = "This is a multi-part message in MIME format.\n\n" . "--{$mime_boundary}\n" . "Content-Type: text/plain; charset=\"iso-8859-1\"\n" . "Content-Transfer-Encoding: 7bit\n\n" . $message . "\n\n"; $message .= "--{$mime_boundary}\n" . "Content-Type: {$type};\n" . " name=\"{$name}\"\n" . "Content-Transfer-Encoding: base64\n\n" . $data . "\n\n" . "--{$mime_boundary}--\n"; if ($type == "image/jpeg") || ($type == "image/jpg") || ($type == "image/gif") || ($type == "image/psd") || ($type == "image/tiff") || ($type == "image/bmp") { }else{ echo "The file is not a supported file type: jpeg, jpg, gif, psd, tiff or bmp"; die; } if (@mail($to, $subject, $message, $headers)) echo "Your request has been sent.<br>"; else echo "Failed to send"; } } else { ?> <meta http-equiv="refresh" content="2;URL=contact.html"> <?php } } ?> |
Quote:
if ($type == "image/jpeg" || $type == "image/jpg" || $type == "image/gif" || $type == "image/psd" || $type == "image/tiff" || $type == "image/bmp") |
^ absolutely correct.
|
sweet thanks guys
|
All times are GMT -7. The time now is 07:17 AM. |
Powered by vBulletin® Version 3.8.8
Copyright ©2000 - 2025, vBulletin Solutions, Inc.
©2000-, AI Media Network Inc123