...

View Full Version : Uploading .swf



Snitz
01-13-2008, 11:24 AM
Hey there,

I have this php script that allows users to upload images to my server, I was wondering how can I tweak it to allow users to upload .swf files as well.

Here is the script



<?php



require_once 'varconfig.php';

require_once 'dbfunctions.php';



if (!isset($_POST['tags']) || trim($_POST['tags']) == '')

{

header('Location: ' . $GLOBALS['appURL'] . '?t=upload_error&error=You have not entered tags.');

exit();

}

else

{

$_POST['tags'] = str_replace(' ', ',', $_POST['tags']);

$_POST['tags'] = explode(',', $_POST['tags']);



foreach ($_POST['tags'] as &$tag)

{

$tag = trim($tag);

}



$_POST['tags'] = ',' . implode(',', $_POST['tags']) . ',';

}



if (!isset($_POST['agree']) || $_POST['agree'] != 1)

{

header('Location: ' . $GLOBALS['appURL'] . '?t=upload_error&error=You must agree that this image is not contains pornography and you have the rights to distribute this image.');

exit();

}



if (is_uploaded_file($_FILES['userfile']['tmp_name']))

{

$approvedTypes = array('image/gif', 'image/jpeg', 'image/jpg', 'image/png', 'image/pjpeg');



if (!in_array($_FILES['userfile']['type'], $approvedTypes))

{

header('Location: ' . $GLOBALS['appURL'] . '?t=upload_error&error=Unsupported file type.');

exit();

}



$originalPath = $GLOBALS['appUploadFolder'] . $_FILES['userfile']['name'];



$resizedFile = md5(uniqid(time())) . '.jpg';

$resizedPath = $GLOBALS['appUploadFolder'] . $resizedFile;



while (file_exists($resizedPath))

{

$resizedFile = md5(uniqid(time())) . '.jpg';

$resizedPath = $GLOBALS['appUploadFolder'] . $resizedFile;

}

/*

echo '<hr>$resizedFile=['.$resizedFile.']';

echo '<hr>$resizedPath=['.$resizedPath.']';

echo '<hr>$originalPath=['.$originalPath.']';

echo '<hr>$_FILES[userfile][tmp_name]=['.$_FILES['userfile']['tmp_name'].']';

die('<hr>temp out of order...');

*/

if (move_uploaded_file($_FILES['userfile']['tmp_name'], $originalPath))

{

if (!resampimagejpg(170, 100, $originalPath, $resizedPath))

{

header('Location: ' . $GLOBALS['appURL'] . '?t=upload_error&error=Unsupported file format.');

exit();

}

//resampleImage(170, 100, $originalPath, $resizedPath, 10);

@unlink($originalPath);



newSticker($_POST['user'], $resizedFile, $_POST['tags']);



header('Location: ' . $GLOBALS['appURL'] . '?t=upload_success');

exit();

}

else

{

header('Location: ' . $GLOBALS['appURL'] . '?t=upload_error&error=Cannot upload file.');

exit();

}

}

else

{

header('Location: ' . $GLOBALS['appURL'] . '?t=upload_error&error=Cannot upload file.');

exit();

}



?>



Thank you.

abduraooft
01-13-2008, 11:34 AM
$approvedTypes = array('image/gif', 'image/jpeg', 'image/jpg', 'image/png', 'image/pjpeg','application/x-shockwave-flash');

Hope this would work.

Snitz
01-13-2008, 11:35 AM
Wouldn't I need to do the resize thing? Like the jpg does.



$resizedFile = md5(uniqid(time())) . '.jpg';

$resizedPath = $GLOBALS['appUploadFolder'] . $resizedFile;



while (file_exists($resizedPath))

{

$resizedFile = md5(uniqid(time())) . '.jpg';

$resizedPath = $GLOBALS['appUploadFolder'] . $resizedFile;

}



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum