gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 18:10:58 25 4
gpt4 key购买 nike

我正在尝试在网站上实现 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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com