<commit_before><?php
// 本类由系统自动生成，仅供测试用途
namespace Home\Controller;
use Think\Controller;
class UploadController extends Controller {
    private $pdo;
    function __construct(){
        $this->pdo = pdo();
    }
    private function index($dir,$filename){
        header('Content-Type: text/javascript');
        if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
            echo(json_encode(array('result'=>'ok','info' => 'POST request method only.')));
            exit;
        }
        if (!$_FILES['file']) {
            echo(json_encode(array('result'=>'ok','info' => 'file field not found.')));
            exit;
        }
        if ($_FILES['file']['error'] !== 0) {
            echo(json_encode(array('result'=>'ok','info' => 'file field found but with error #' . $_FILES['file']['error'] . '.')));
            exit;
        }
        return move_uploaded_file( $_FILES['file']['tmp_name'], $dir.$filename);
        
    }
    public function thumb(){
        if (!file_exists(env('THUMB_DIR'))) {
            mkdir(env('THUMB_DIR'));         
        }
        $statement = $this->pdo->prepare("select title from draft where id=?");
        $statement->execute(array($_POST['id']));
        $r = $statement->fetch();
        if(!$r['title']){
            echo json_encode(array('result'=> 'error','info'=>'no such file','r'=>$r));
            return ;
        }
        $filename = $this->get_thumb_name($r['title']).'.jpg';
        $save_file_result = $this->index(env('THUMB_DIR'), $filename);
        if(!$save_file_result){
            echo json_encode(array('result' => 'error','info' => 'save file failure'));
            return ;
        }
        echo(<commit_msg>show save file error details<commit_after><?php
// 本类由系统自动生成，仅供测试用途
namespace Home\Controller;
use Think\Controller;
class UploadController extends Controller {
    private $pdo;
    function __construct(){
        $this->pdo = pdo();
    }
    private function index($dir,$filename){
        header('Content-Type: text/javascript');
        if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
            echo(json_encode(array('result'=>'ok','info' => 'POST request method only.')));
            exit;
        }
        if (!$_FILES['file']) {
            echo(json_encode(array('result'=>'ok','info' => 'file field not found.')));
            exit;
        }
        if ($_FILES['file']['error'] !== 0) {
            echo(json_encode(array('result'=>'ok','info' => 'file field found but with error #' . $_FILES['file']['error'] . '.')));
            exit;
        }
        return move_uploaded_file( $_FILES['file']['tmp_name'], $dir.$filename);
        
    }
    public function thumb(){
        if (!file_exists(env('THUMB_DIR'))) {
            mkdir(env('THUMB_DIR'));         
        }
        $statement = $this->pdo->prepare("select title from draft where id=?");
        $statement->execute(array($_POST['id']));
        $r = $statement->fetch();
        if(!$r['title']){
            echo json_encode(array('result'=> 'error','info'=>'no such file','r'=>$r));
            return ;
        }
        $filename = $this->get_thumb_name($r['title']).'.jpg';
        $save_file_result = $this->index(env('THUMB_DIR'), $filename);
        if(!$save_file_result){
            echo json_encode(array('result' => 'error','info' => 'save file failure' . env('THUMB_DIR') . $filename));
            return ;
        }
        echo(
{'fraction_non_alphanumeric': 0.19278169014084506, 'fraction_numerical': 0.0005868544600938967, 'mean_word_length': 2.4750254841997963, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 39, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4819225', 'n_tokens_mistral': 1018, 'n_tokens_neox': 1024, 'n_words': 187}