PHP JQuery: Where to specify uploadify destination folder

Posted by Eamonn on Stack Overflow See other posts from Stack Overflow or by Eamonn
Published on 2012-07-10T03:08:31Z Indexed on 2012/07/10 3:15 UTC
Read the original article Hit count: 240

Filed under:
|
|

I have an uploadify script running, basic setup. Works fine when I hard code the destination folder for the images into uploadify.php - now I want to make that folder dynamic. How do I do this?

I have a PHP variable $uploadify_path which contains the path to the folder I want. I have switched out my hard coded $targetPath = path/to/directory for $targetPath = $uploadify_path in both uploadify.php and check_exists.php, but it does not work. The file upload animation runs, says it is complete, yet the directory remains empty. The file is not hiding out somewhere else either.

I see there is an option in the Javascript to specify a folder. I tried this also, but to no avail.

If anyone could educate me on how to pass this variable destination to uploadify, I'd be very grateful.

I include my current code for checking (basically default):

The Javascript

<script type="text/javascript">
$(function() {

    $('#file_upload').uploadify({
        'swf'      : 'uploadify/uploadify.swf',
        'uploader' : 'uploadify/uploadify.php',
        // Put your options here
    });
});
</script>

uploadify.php

$targetPath = $_SERVER['DOCUMENT_ROOT'] . $uploadify_path; // Relative to the root

if (!empty($_FILES)) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetFile = $targetPath . $_FILES['Filedata']['name'];

    // Validate the file type
    $fileTypes = array('jpg','jpeg','gif','png'); // File extensions
    $fileParts = pathinfo($_FILES['Filedata']['name']);

    if (in_array($fileParts['extension'],$fileTypes)) {
        move_uploaded_file($tempFile,$targetFile);
        echo '1';
    } else {
        echo 'Invalid file type.';
    }
}

© Stack Overflow or respective owner

Related posts about php

Related posts about jQuery