I installed Uploadify UI on my site so I can allow user to upload files to my site. It is working now but the problem is that it uploads files sometimes and sometimes it does not. So I can upload an png file and it will work no problems. but when I upload excel file it will allow some to be uploaded and some it work allow it.
I am not sure what can I check to see what is causing the issue.
I have tried to turn the debuger on 'debug' : true but that did not give me any clues. I also looked at my php logs and there was no error/warnings there.
I am not sure what else I can check but I will apreshiate any type of help with this.
Here is my javascript code to set it up
<?php $timestamp = time();?>
<script type="text/javascript">
$(function() {
$('#file_upload').uploadify({
'formData' : {
'timestamp' : '<?php echo $timestamp;?>',
'token' : '<?php echo md5($timestamp);?>',
'upload_path': 'ticketing_center/',
'allowed_extentions': 'jpg,jpeg,gif,PNG,JPG,png,JPEG, jpeg,zip,rar,doc,docx,cvs,xls,xlsx,txt'
},
'auto' : true,
'debug' : true,
'swf' : '../../includes/uploadify.swf',
'uploader' : '../../includes/uploadify.php',
'fileSizeLimit' : '50MB',
'fileTypeExts' : '*.gif; *.jpg; *.JPG; *.png; *.PNG; *.JPEG; *.jpeg; *.zip; *.rar; *.doc; *.docx; *.cvs; *.xls; *.xlsx; *.txt;',
'onUploadSuccess' : function(file, data, response) {
if(data != 'INVALID'){
$('#attached_files').append('<input type="hidden" name="attachments[]" value="'+ $.trim(data) +'" />');
} else {
alert('Invalid File Type');
}
}
});
});
</script>
the following is my PHP script
<?php
$targetFolder = '';
$verifyToken = '100';
$actualToken = '';
$fileTypes = array('jpg','jpeg','gif','png');
if(isset($_POST['upload_path'])){
$targetFolder = $_POST['upload_path'];
}
if(isset($_POST['timestamp'])){
$verifyToken = md5($_POST['timestamp']);
}
if(isset($_POST['token'])){
$actualToken = $_POST['token'];
}
if(isset($_POST['allowed_extentions'])){
$types = explode(',', $_POST['allowed_extentions']);
if(count($types) > 0 ){
$fileTypes = $types;
}
}
if (!empty($_FILES) && $actualToken == $verifyToken) {
$tempFile = $_FILES['Filedata']['tmp_name'];
$targetPath = ROOT_FIXED . UPLOAD_DIR . $targetFolder; //$_SERVER['DOCUMENT_ROOT']
$targetPath = str_replace( "//", "/", $targetPath);
$new_filename = USER_ID . '_' . time() . '_' . str_replace(" ", "_", $_FILES['Filedata']['name']);
$targetFile = $targetPath . $new_filename;
// Validate the file type
//$fileTypes = array('jpg','jpeg','gif','png'); // File extensions
$fileParts = pathinfo($new_filename); //str_replace(" ", "_", $_FILES['Filedata']['name'])
if (in_array($fileParts['extension'],$fileTypes)) {
move_uploaded_file($tempFile,$targetFile);
echo trim($new_filename);
} else {
echo 'INVALID';
}
}
?>
Thanks for your time and help