我是新手,本来是学习java的,但刚一进公司就搞php网页,一点都不懂啊,这两天经理让我做个上传压缩文件的按钮,可以上传,但在目标文件里却接收不到我上传的文件,我把代码复制过来,希望各路大侠能给指点下,感激不尽。
<html>
<link href="css/style.css?t=20130428" type="text/css" rel="stylesheet" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.8.3.js"></script>
<script src="js/jquery.uploadify.js" type="text/javascript"></script>
<script src="js/jquery.uploadify-3.1.min.js" type="text/javascript"></script>
<li id="tpfile" style="background:none; cursor:pointer;" >
<form >
<div id="queue"></div>
<input id="file_uploadtp" name="file_uploadtp" type="file" multiple="true">
</form>
<script type="text/javascript">
$(function() {
$('#file_uploadtp').uploadify({
'formData' : {
'uuid' : ''+uuid
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadifytp.php',
'method' : 'get',
'successTimeout' : 10,
'fileSizeLimit' : '1GB',
'fileTypeExts': '*.zip;*.rar;*.doc',
'fileTypeDesc' : '请选择*.zip;*.rar;*.doc的文件',
'width':'50px',
'buttonText':'批量上传',
'onUploadComplete' : function(file) {
},'onUploadSuccess': function(event, response, status) {
if(response==1){
spsc="1";
alert("文件类型不符合要求");
}else {
alert("文件上传成功");
}
}
});
});
</script>
</li>
</html><?php
/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
$targetFolder = '/nrgl/photos'; // Relative to the root
$uuid=$_GET['uuid'];//$verifyToken = md5('unique_salt' . $_POST['timestamp']);
//if (!empty($_FILES) && $_POST['token'] == $verifyToken) {$rand=rand(0,999999999);//if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile =rtrim($targetPath,'/') . '/'.$rand.'.' .substr($_FILES['Filedata']['name'],-3,3);
// Validate the file type
$fileTypes = array('zip','rar','doc'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo $targetFile;
} else {
echo '1';
}
<html>
<link href="css/style.css?t=20130428" type="text/css" rel="stylesheet" />
<link href="style.css" rel="stylesheet" type="text/css" />
<script src="js/jquery-1.8.3.js"></script>
<script src="js/jquery.uploadify.js" type="text/javascript"></script>
<script src="js/jquery.uploadify-3.1.min.js" type="text/javascript"></script>
<li id="tpfile" style="background:none; cursor:pointer;" >
<form >
<div id="queue"></div>
<input id="file_uploadtp" name="file_uploadtp" type="file" multiple="true">
</form>
<script type="text/javascript">
$(function() {
$('#file_uploadtp').uploadify({
'formData' : {
'uuid' : ''+uuid
},
'swf' : 'uploadify.swf',
'uploader' : 'uploadifytp.php',
'method' : 'get',
'successTimeout' : 10,
'fileSizeLimit' : '1GB',
'fileTypeExts': '*.zip;*.rar;*.doc',
'fileTypeDesc' : '请选择*.zip;*.rar;*.doc的文件',
'width':'50px',
'buttonText':'批量上传',
'onUploadComplete' : function(file) {
},'onUploadSuccess': function(event, response, status) {
if(response==1){
spsc="1";
alert("文件类型不符合要求");
}else {
alert("文件上传成功");
}
}
});
});
</script>
</li>
</html><?php
/*
Uploadify
Copyright (c) 2012 Reactive Apps, Ronnie Garcia
Released under the MIT License <http://www.opensource.org/licenses/mit-license.php>
*/
$targetFolder = '/nrgl/photos'; // Relative to the root
$uuid=$_GET['uuid'];//$verifyToken = md5('unique_salt' . $_POST['timestamp']);
//if (!empty($_FILES) && $_POST['token'] == $verifyToken) {$rand=rand(0,999999999);//if (!empty($_FILES) && $_POST['token'] == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = $_SERVER['DOCUMENT_ROOT'] . $targetFolder;
$targetFile =rtrim($targetPath,'/') . '/'.$rand.'.' .substr($_FILES['Filedata']['name'],-3,3);
// Validate the file type
$fileTypes = array('zip','rar','doc'); // File extensions
$fileParts = pathinfo($_FILES['Filedata']['name']);
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo $targetFile;
} else {
echo '1';
}
请确认该目录真实存在,并有写权限