|
先上代码:
Controller:
function upload()
{
$this->load->view('upload/index');
}
function do_upload()
{
$targetFolder = $this->config->base_url('uploads');
$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.';
}
}
}
function check_exists()
{
$targetFolder = $this->config->base_url('uploads');
if (file_exists($_SERVER['DOCUMENT_ROOT'] . $targetFolder . '/' . $_POST['filename'])) {
echo 1;
} else {
echo 0;
}
}
View:
<form>
<div id="queue"></div>
<input id="file_upload" name="file_upload" type="file" multiple="true">
</form>
<script type="text/javascript">
<?php $timestamp = time();?>
$(function() {
$('#file_upload').uploadify({
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5('unique_salt' . $timestamp);?>'
},
'swf' : '<?php echo $this->config->base_url('swf/uploadify.swf')?>',
'uploader' : '<?php echo $this->config->site_url('smile/do_upload')?>'
});
});
</script>
请问为什么还是上传不了文件呢?而且查看了很久demo,但是不知道 check_exists这个怎么使用, 我将uploadify里面的两个php弄成了controller里面的两个function来调用,但是不知道怎么弄,谢谢
|
|