- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试在网站上实现 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 服务器上文件的屏幕截图:
编辑
我尝试上传 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/
我有以下正则表达式 /[a-zA-Z0-9_-]/ 当字符串只包含从 a 到z 大小写、数字、_ 和 -。 我的代码有什么问题? 能否请您向我提供一个简短的解释和有关如何修复它的代码示例? //var
我是一名优秀的程序员,十分优秀!