javascript - 上传成功但没有上传文件?

标签 javascript php jquery uploadify directory-permissions

我正在尝试在网站上实现 uploadify。

它说文件已上传,但当我查看上传文件夹时,什么也没有。

我读过其他类似的帖子,但没有运气。

我确实读过this answer另一个问题:

I had similar problems on a Linux machine. It turned out that the PHP configuration on my server was the cuplrit. PHP was running in SAFE MODE. As I had uploaded the Uploadify scripts via FTP, so script files were stored in the file system with my FTP user details. Since PHP's temp folder was owned by the server root, I had a UID mismatch, i.e. the temporary upload file was attributed to root while the upload script that tried to move it was owned by the FTP user. That fragged it.

To resolve this I changed the ownership of the uploadify php script to root and from there on it worked.

我对服务器端编码知之甚少,因为我更多的是前端人员。如何更改权限?我正在使用 1&1 托管。

以下是 FileZilla 服务器上文件的屏幕截图:

FileZilla Screenshot

编辑

我尝试上传 ZIP 文件,它说上传成功,但没有上传。但是,我想知道我的脚本是否有错误,因为 PHP 脚本中的这一行不应该允许我上传 ZIP 文件:

// Validate the file type
$fileTypes = array('jpg','jpeg','gif','png'); // File extensions

脚本不应该拒绝 zip 文件吗?

下面是我正在使用的代码,以防脚本出现错误,而不是我的服务器出现错误:

JS

$(function() {
    $('#file_upload').uploadify({
        'swf'      : 'uploadify.swf',
        'uploader' : 'uploadify.php',
        'onUploadSuccess' : function(file, data, response) {
            alert('The file ' + file.name + ' was successfully uploaded with a response of ' + response + ':' + data);
        } 
    });
});

PHP

<?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.';
}
}
?>

最佳答案

看来问题出在 token 验证码上。如果您删除该功能,则应该完成上传:)

您可以通过注释掉 if() 比较来删除它吗?

if (!empty($_FILES) && $_POST['token'] == $verifyToken) { 行更改为:

if (!empty($_FILES)/* && $_POST['token'] == $verifyToken */) {

关于javascript - 上传成功但没有上传文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19718895/

相关文章:

jquery - FullCalendar "view"可缓存

javascript - 如何为正在查看的网站动态更改 css 样式表?

php - laravel 5.1 中中间件路由组和命名空间路由组之间的区别?

php - 在图表上显示来自外部网站抓取的 JSON

php - 无法通过 PHP (Android) 上传名称中有空格的文件

javascript - jQuery 和 long int id

javascript - Node.js 模块的异步初始化

javascript - Rails 和 JavaScript 之间的数组

javascript - Ajax GET 请求 Laravel 5.2

php - jQuery Masonry - 流体布局问题