Problem in converting .doc file in to plain text

Discussion in 'PHP' started by learnerabn, Nov 24, 2010.

  1. #1
    hi all,

    I am using ajax uploadify to upload files in server.that works fine but after uplading the file i want to convert the .doc file into plain text and store it in db.Here araises the problem the fishy thing here is it worked well till this morning i dont know why it was not woring now.

    the uploadify codes are

    $("#uploadify").uploadify({
    		'uploader'       : 'images/uploadify.swf',
    		'script'         : 'resume-upload.php',
    		'cancelImg'      : 'images/cancel.png',
    		'folder'         : '',
    		'queueID'        : 'fileQueue',
    		'auto'           : true,
    		'multi'          : true,
    		'buttonText'	 : 'tex',
    		'buttonImg'		 : 'images/file_attach.png',
    		//'rollover'	 : true,
    		'height'		 : '15',
    		//'hideButton'	 : true,
    		'fileDesc'		 : 'txt, rtf, doc, docx, xls, xlsx, ppt, pptx, pdf, jpg, jpeg, gif, png',
    		'fileExt'		 : '*.txt;*.rtf;*.doc;*.docx;*.xls;*.xlsx;*.ppt;*.pptx;*.pdf;*.jpg;*.jpeg;*.gif;*.png',
    		
    		onSelect: function(event, queueID, fileObj) { 
    			
    			var len = $('div#attachment').find('div.line_attach').length;
    			if(len >= 2){
    				var error = "You are reached maximum of attachment.";
    				show_error_msg(error);
    				return;
    			}
    			
    			var valid_extensions = /(.txt|.rtf|.doc|.docx|.xls|.xlsx|.ppt|.pptx|.pdf|.jpg|.jpeg|.gif|.png)$/i;
    			if (valid_extensions.test(fileObj.name)) return true;
    			
    			show_error_msg('The selected file is of the wrong type.');
    			return false;
    		},
    		onComplete: function(event, queueID, fileObj, response) { 
    			//$("div#attachment").html(fileObj.name);
    			
    			//console.log(response);
    			var error_string = "invalid_file_type";
    			if (response.indexOf(error_string) != -1) {			
    				
    				show_error_msg('Invalid file type.');
    				return;
    			}
    			
    			var len = $('div#attachment').find('div.line_attach').length;
    			if(len >= 5){
    				show_error_msg('You are reached maximum of attachment.');
    				return;
    			}	
    			
    			var filesize = parseInt(fileObj.size/1000);
    			
    			alert('ent');
    			
    			var temp = "";
    			temp = '<div class="line_attach">'+  fileObj.name +' ('+ filesize +' kb) <input type="hidden" name="original_file_name[]" value="'+ fileObj.name +'" /><input type="hidden" name="system_file_name[]" value="'+ response +'" />&nbsp; <a href="javascript:void(0);" title="Remove" class="r_line_attach"><img src="images/mclose.png" alt="Remove" title="Remove" /></a></div>';
    			
    					
    			$('div#attachment').append(temp);
    			
    		}
    	});
    Code (markup):

    the resume_upload.php file is

    <?php
    	require_once('common/jb_db_conn.php');
       
    	function upload_files($file_name, $tmp_name) {
    	
    	
    		$ext = array("txt","rtf", "doc");
    		
    		//print $file_name .",". $tmp_name;
    		if($file_name == "")
    			return;
    		
    		$file_ext = strtolower(end(explode(".", $file_name)));
    		
    		if(!in_array($file_ext, $ext))
    			return "";
    		
    		//	check file available or not
    		while(true) {
    		
    			if(!file_exists("upload_files/inbox/".$file_name))
    				break;
    		
    			$file_name = str_replace(".", "", microtime(true)) .".". $file_ext;
    		}//	end while
    		
    		$log_file = "/inbox_upload.log";
    		
    		$content = "Tmp Name: ".$tmp_name;
    		$content .= "\r\nOriginal Name:upload_files/inbox/".$file_name;
    		//file_put_contents($log_file, $content, FILE_APPEND);
    		
    		//	move upload file
    		if(!move_uploaded_file($tmp_name, "upload_files/inbox/".$file_name)) return;
    		return $file_name;
    	
    	}//	end function
    	
    	function get_resume_text_from_file($path, $file_name) {
    
    	$resume_text = "";
    	$ext = end(explode(".", $file_name));
    	
    	switch($ext) {
    	
    		case 'doc':
    		case 'rtf':
    			$word_file_path = $path."".$file_name;
    			$txt_file_path = $path."raja-".time().".txt";
    			//print "Antiword: antiword -f -t ".$word_file_path ." > ".$txt_file_path);
    			exec("antiword -f -t ".$word_file_path ." > ".$txt_file_path);			
    			$resume_text = file_get_contents($word_file_path);		
    			unlink($txt_file_path);
    			//print $resume_text;
    			//exit();
    			break;
    		case 'txt':
    			$txt_file_path = $path.$file_name;
    			$resume_text = file_get_contents($txt_file_path);
    			break;
    		default:
    			$resume_text = "";
    			break;
    	}
    	
    	return $resume_text;
    }
    	$uploaded_file_name = "";
    	
    	$files = $_FILES['Filedata'];
    	
    	$file_name = upload_files($files['name'], $files['tmp_name']);
    	$resume_content = "";
    	$resume_content = get_resume_text_from_file("upload_files/inbox/", $file_name);
    	$query = "update jb_resumes set status = 1 where profile_id = '369'";
    	mysql_query($query) or die(mysql_error());
    	if($resume_content == '')
    	$resume_content= "not set";
    	$query = "insert into jb_resumes (display_resume_file_name,original_resume_file_name,resume_content,profile_id,status) values('".$files['name']."','".$file_name."','".$resume_content."','369','0')";
    	mysql_query($query) or die(mysql_error());
    	$date = date("Y-M-d H:i:s");
    	$sql_qry = "update jb_profile_status set attached_resume ='0', modified ='".$date."' where profile_id = 369";
    	mysql_query($sql_qry) or 	die(mysql_error());
    	//echo "1";
    	if($file_name) {
    		print $file_name;
    	}
    	else {
    		print "invalid_file_type";
    	}	
    	
    	exit();		
    ?>
    Code (markup):
    here it works well upto the code
    $query = "update jb_resumes set status = 1 where profile_id = '369'";
    mysql_query($query) or die(mysql_error());

    can any body help me in this?

    Thanks in advance.
     
    learnerabn, Nov 24, 2010 IP
  2. Saakshi Mahajan

    Saakshi Mahajan Greenhorn

    Messages:
    1
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    21
    #2
    did you find solution to this problem, i also want automated conversion of files with uploadify
     
    Saakshi Mahajan, Feb 16, 2014 IP