GoFuckYourself.com - Adult Webmaster Forum

GoFuckYourself.com - Adult Webmaster Forum (https://gfy.com/index.php)
-   Fucking Around & Business Discussion (https://gfy.com/forumdisplay.php?f=26)
-   -   please help me with simple php (https://gfy.com/showthread.php?t=848742)

snowpimp 08-18-2008 11:46 AM

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...

just a punk 08-18-2008 11:54 AM

That should work, but it depends on what exactly is stored in $type variable.

Aric 08-18-2008 11:56 AM

PHP Code:

$allowed_types = array("image/jpeg""image/jpg""image/gif""image/psd","image/tiff","image/bmp");
if (
in_array($type$allowed_types)) {
    
do_something;



Bro Media - BANNED FOR LIFE 08-18-2008 11:57 AM

Quote:

Originally Posted by cyberxxx (Post 14624733)
That should work, but it depends on what exactly is stored in $type variable.

bingo. whats $type ?

snowpimp 08-18-2008 11:59 AM

$type = $_FILES['filename']['type'];

just a punk 08-18-2008 12:06 PM

Quote:

Originally Posted by snowpimp (Post 14624758)
$type = $_FILES['filename']['type'];

Should be working then. Are you getting any error message?

snowpimp 08-18-2008 12:33 PM

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 }
}
?>

Aric 08-18-2008 12:38 PM

Quote:

if ($type == "image/jpeg")
|| ($type == "image/jpg")
|| ($type == "image/gif")
|| ($type == "image/psd")
|| ($type == "image/tiff")
|| ($type == "image/bmp")
It's a bracketing problem.

if ($type == "image/jpeg"
|| $type == "image/jpg"
|| $type == "image/gif"
|| $type == "image/psd"
|| $type == "image/tiff"
|| $type == "image/bmp")

UniqueD 08-18-2008 12:40 PM

^ absolutely correct.

snowpimp 08-18-2008 12:54 PM

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