Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Uploading .swf

  1. #1
    Regular Coder
    Join Date
    Jul 2004
    Location
    Lebanon
    Posts
    223
    Thanks
    6
    Thanked 0 Times in 0 Posts

    Uploading .swf

    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 Code:
    <?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(170100$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.

  • #2
    Supreme Master coder! abduraooft's Avatar
    Join Date
    Mar 2007
    Location
    N/A
    Posts
    14,861
    Thanks
    160
    Thanked 2,223 Times in 2,210 Posts
    Blog Entries
    1
    Code:
    $approvedTypes = array('image/gif', 'image/jpeg', 'image/jpg', 'image/png', 'image/pjpeg','application/x-shockwave-flash');
    Hope this would work.
    The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)

  • #3
    Regular Coder
    Join Date
    Jul 2004
    Location
    Lebanon
    Posts
    223
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Wouldn't I need to do the resize thing? Like the jpg does.

    PHP Code:
    $resizedFile md5(uniqid(time())) . '.jpg';

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



        while (
    file_exists($resizedPath))

        {

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

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

        } 


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •