PHP 用uploadify插件在客戶端寫好代碼之后,上傳文件老是出現(xiàn)302的錯誤網(wǎng)上搜了大把的資料 ?但都是很模糊的概念 ?不知道有沒有小伙伴遇到過同樣的問題?求解答?。。?*
以下是客戶端代碼
*/<input?id="file_upload"?name="file_upload"?type="file"?multiple="true">?
<script?type="text/javascript">????????
<?php?$timestamp?=?time();?>
????????$(function()?{
????????????$('#file_upload').uploadify({?
??????????????'formData'?????:?{??
???????????????????'timestamp'?:?'<?php?echo?$timestamp;?>',???
????????????????????'token'?????:?'<?php?echo?md5('unique_salt'?.?$timestamp);?>'
????????????????},?
?????????????????'buttonText':'上傳文件',?
??????????????????'fileTypeExts'?:?'*.doc;*.docx;*.pdf;',??
??????????????????'swf'??????:?'<?php?echo?base_url("js/uploadify/uploadify.swf");?>',??
???????????????????'uploader'?:?'<?php?echo?base_url('module/files/main/uploadify?type=1')?>',????????????????'onUploadSuccess'?:?function(file,?data,?response)?{
?????????????????????alert(data);
????????????????},
????????????});
????????});
????</script>
____________分割線______________/*
以下是服務(wù)端代碼
*/public?function?uploadify()?{?
????$type?=?$_GET['type'];?
????$targetPath?=?'./uploads/uploadify_file';?
????$verifyToken?=?md5('unique_salt'?.?$_POST['timestamp']);?
????if?(!empty($_FILES)?&&?$_POST['token']?==?$verifyToken)?{??
????????$tempFile?=?$_FILES['Filedata']['tmp_name'];?
?????????if?(!file_exists($targetPath))?{
????????????????@mkdir($targetPath);
????????????????chmod($targetPath,?0777);
?????????}???
?????????$file_name?=?$_FILES['Filedata']['name'];
?????????$hz?=?explode(".",$_FILES['Filedata']['name']);
?????????$targetFile?=?rtrim($targetPath,'/')?.?'/'?.?md5(time()).".".$hz[1];?
?????????$fileTypes?=?array('doc','docx','pdf');?//?File?extensions
?????????$fileParts?=?pathinfo($_FILES['Filedata']['name']);?
?????????if?(in_array($fileParts['extension'],$fileTypes))?{??
?????????????if(move_uploaded_file($tempFile,$targetFile)){???
?????????????????$file_message?=?array(???
?????????????????????'file_name'=>$file_name,
?????????????????????'file_creat_time'=>time(),
?????????????????????'file_url'=>?$targetFile,
?????????????????????'file_type'=>$type
????????????????????????);
??????????????????$res?=?$this->files_Model->insert($file_message);
??????????????????if?(!$res)?{
??????????????????????echo?'文件'.$file_message['name'].'保存失敗';
??????????????????????return?FALSE;
????????????????????}else{
????????????????????????echo?'上傳成功';
????????????????????????eturn?TRUE;
????????????????????}
????????????????}else{?
????????????????????echo?'啊哦!文件移動失敗了,請檢查文件路徑';
????????????????????return?FALSE;
????????????????}
????????????}?else?{
????????????????cho?'文件類型不匹配哈!';
????????????????return?FALSE;
????????????}
????????}
????}
添加回答
舉報
0/150
提交
取消