正在尝试上传以与Wordpress合作。我已经在wordpress管理区的metabox中实现了文档中的代码。
我可以“选择文件”并上传它,Uploadify将显示进度,但当我检查目标文件夹时,它是空的。该文件夹有chmod 777,因此我不知道可能出了什么问题。。
感谢所有帮助。
<link href="<?php echo get_stylesheet_directory_uri() ?>/uploadify/uploadify.css" type="text/css" rel="stylesheet" />
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri() ?>/uploadify/jquery-1.4.2.min.js"></script>
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri() ?>/uploadify/swfobject.js"></script>
<script type="text/javascript" src="<?php echo get_stylesheet_directory_uri() ?>/uploadify/jquery.uploadify.v2.1.4.min.js"></script>
<script type="text/javascript">
$(document).ready(function() {
$(\'#file_upload\').uploadify({
\'uploader\' : \'<?php echo get_stylesheet_directory_uri() ?>/uploadify/uploadify.swf\',
\'script\' : \'<?php echo get_stylesheet_directory_uri() ?>/uploadify/uploadify.php\',
\'cancelImg\' : \'<?php echo get_stylesheet_directory_uri() ?>/uploadify/cancel.png\',
\'folder\' : \'<?php echo get_bloginfo(\'url\') ?>/wp-content/uploads\',
\'auto\' : true
});
});
</script>
<input id="file_upload" name="file_upload" type="file" />
上传。php
<?php
/*
if (!empty($_FILES)) {
$tempFile = $_FILES[\'Filedata\'][\'tmp_name\'];
$targetPath = $_SERVER[\'DOCUMENT_ROOT\'] . $_REQUEST[\'folder\'] . \'/\';
$targetFile = str_replace(\'//\',\'/\',$targetPath) . $_FILES[\'Filedata\'][\'name\'];
// $fileTypes = str_replace(\'*.\',\'\',$_REQUEST[\'fileext\']);
// $fileTypes = str_replace(\';\',\'|\',$fileTypes);
// $typesArray = split(\'\\|\',$fileTypes);
// $fileParts = pathinfo($_FILES[\'Filedata\'][\'name\']);
// if (in_array($fileParts[\'extension\'],$typesArray)) {
// Uncomment the following line if you want to make the directory if it doesn\'t exist
// mkdir(str_replace(\'//\',\'/\',$targetPath), 0755, true);
move_uploaded_file($tempFile,$targetFile);
echo str_replace($_SERVER[\'DOCUMENT_ROOT\'],\'\',$targetFile);
// } else {
// echo \'Invalid file type.\';
// }
}
?>
最合适的回答,由SO网友:Bainternet 整理而成
你的上传。php都在注释中,因此它并没有真正保存文件。
更改为:
<?php
if (!empty($_FILES)) {
$tempFile = $_FILES[\'Filedata\'][\'tmp_name\'];
$targetPath = $_SERVER[\'DOCUMENT_ROOT\'] . $_REQUEST[\'folder\'] . \'/\';
$targetFile = str_replace(\'//\',\'/\',$targetPath) . $_FILES[\'Filedata\'][\'name\'];
$fileTypes = str_replace(\'*.\',\'\',$_REQUEST[\'fileext\']);
$fileTypes = str_replace(\';\',\'|\',$fileTypes);
$typesArray = split(\'\\|\',$fileTypes);
$fileParts = pathinfo($_FILES[\'Filedata\'][\'name\']);
if (in_array($fileParts[\'extension\'],$typesArray)) {
// Uncomment the following line if you want to make the directory if it doesn\'t exist
// mkdir(str_replace(\'//\',\'/\',$targetPath), 0755, true);
move_uploaded_file($tempFile,$targetFile);
echo str_replace($_SERVER[\'DOCUMENT_ROOT\'],\'\',$targetFile);
} else {
echo \'Invalid file type.\';
}
}
?>
还要确保验证文件类型,因为我有一个网站在黑客上传了带有uploadify的php shell脚本后遭到了黑客攻击。