Uploadify destination file path

483 Views Asked by At

Hi I'm working with this uploadify thing and i'm not getting it right. I have checked the code and i didn't find any error. its really making me mad now. The folder where the folder is located " E:\xampp\htdocs\officework\uploadify\uploads " where 'uploads' is my destination folder name. I really need your help. Thank you very much Her is the code upload.php

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Uploadify</title>




<script type="text/javascript" src="uploadify/jquery.uploadify.min.js"> </script>
<script type="text/javascript" src="uploadify/uploadify.css"> </script>
<script type="text/javascript" src="uploadify/check-exists.php"> </script>
<script type="text/javascript" src="uploadify/uploadify.swf"> </script>
<script type="text/javascript" src="uploadify/jquery.uploadify.js"></script>
<script type="text/javascript" src="uploadify/uploadify.php"> </script>
<script type="text/javascript" src="uploadify/uploadify-cancel.png"> </script>
<script> 
$(document).ready(function(){
    $('#file_upload').uploadify({
'fileObjName' : 'the_files',
'method' : 'post',
'swf': 'uploadify/uploadify.swf',
'uploader': 'uploadify/uploadify.php',
'check' : '  uploadify/check-exists.php',
'canceling':'uploadify/uploadify-cancel.png',
 'formData' : {'uploads':'localhost/officework/uploadify'},
//'folder' : '/uploads',

'onUploadStart' : function(file) {
            alert('Starting to upload ' + file.name);
        },
'onUploadComplete': function(event, queueID, fileObjName, response, data) 

{
    alert ('you have uploaded ' + fileObj.name + ' to ' + fileObj.filePath + '.'); 
filename="+fileObj.name+"&targetpath="+fileObj.targetPath; //Here you can do a javascript redirect
},

    'onUploadSuccess' : function(file, data, response) {
        alert('The file with name'+file.name + 'was saved to with response:' + response +':'+ data);
    }


});

});
</script>





</head>

<body>


<input type="file" name="file_upload" id="file_upload" />


</body>
</html>

uploadify.php

$targetFolder = '/uploads'; // Relative to the root

$verifyToken = md5('unique_salt' . $_POST['timestamp']);

if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
    $tempFile = $_FILES['Filedata']['tmp_name'];
    $targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
    $targetFile = rtrim($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.';
    }
}
?>

check-exists.php

$targetFolder = '/uploads'; // Relative to the root and should match the upload folder in the uploader script

if (file_exists($_SERVER['DOCUMENT_ROOT'] . $targetFolder . '/' . $_POST['filename'])) {
    echo 1;
} else {
    echo 0;
}
?>
0

There are 0 best solutions below