上传目标文件路径

时间:2017-05-23 07:59:26

标签: javascript php uploadify

嗨,我正在处理这个uploadify事情,我说得不对。我检查了代码,但没有发现任何错误。它真的让我生气了。文件夹所在的文件夹“E:\ xampp \ htdocs \ officework \ uploadify \ uploads”,其中“uploads”是我的目标文件夹名称。我真的需要你的帮助。非常感谢你  她是代码 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.';
    }
}
?>

签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 个答案:

没有答案