4 Commits 15181577c3 ... 6c4c614338

Author SHA1 Message Date
  omidrezav 6c4c614338 Modified readme and composer.json file to introduce customized package correctly 5 years ago
  omidrezav 7c3301b1ce Merge branch 'master' of https://gogs.tamadco.com:3000/omidrezav/resumablephp 5 years ago
  omidrezav 07f9dc1547 Merge branch 'va_customizations' 5 years ago
  omidrezav 303744033f Changed Resumable class to make it compatible with wordpress/fantastic 5 years ago
3 changed files with 54 additions and 4 deletions
  1. 2 2
      composer.json
  2. 2 1
      readme.md
  3. 50 1
      src/Resumable.php

+ 2 - 2
composer.json

@@ -1,6 +1,6 @@
 {
 {
-  "name": "dilab/resumable.php",
-  "description": "PHP package for Resumable.js",
+  "name": "omidfarahani/resumablephp",
+  "description": "PHP package for Resumable.js customized to comply with wordpress/fantastic",
   "authors": [
   "authors": [
     {
     {
       "name": "xu ding",
       "name": "xu ding",

+ 2 - 1
readme.md

@@ -1,11 +1,12 @@
 # PHP backend for resumable.js
 # PHP backend for resumable.js
+## Customized to comply with wordpress/fantastic
 
 
 
 
 ## Installation
 ## Installation
 
 
 To install, use composer:
 To install, use composer:
 
 
-``` composer require dilab/resumable.php ```
+``` composer require omidfarahani/resumablephp ```
 
 
 
 
 ## How to use
 ## How to use

+ 50 - 1
src/Resumable.php

@@ -217,7 +217,56 @@ class Resumable
         if (null !== $this->filename) {
         if (null !== $this->filename) {
             $finalFilename = $this->createSafeFilename($this->filename, $filename);
             $finalFilename = $this->createSafeFilename($this->filename, $filename);
         } else {
         } else {
-            $finalFilename = $filename;
+            global $wpdb;
+            
+            $extension = $this->findExtension($filename);
+            $last_request_file_id = get_option( 'last_request_file_id', 0 );
+            $request_file_id = $last_request_file_id + 1;
+            update_option( 'last_request_file_id', $request_file_id );
+            $file_name = "res_" . uniqid() . $request_file_id . "." . $extension;
+            $file_rel_path = determin_request_file_upload_folder() . '/' . $file_name;
+
+            $finalFilename = $file_name;
+
+            $sql = "SELECT form_value
+              FROM {$wpdb->prefix}fantastic_analysis_requests_info
+              WHERE request_id=%d
+              AND form_field='_result_files'";
+            $files = $wpdb->get_var( $wpdb->prepare( $sql, $_POST['rid'] ) );
+
+            if( $files == '' ) $files = serialize( array() );
+            $files = unserialize( $files );
+            $files[] = $file_rel_path;
+            $files = serialize( $files );
+            $sql = "SELECT COUNT(*)
+              FROM {$wpdb->prefix}fantastic_analysis_requests_info
+              WHERE request_id=%d
+              AND form_field='_result_files'";
+            if( $wpdb->get_var( $wpdb->prepare( $sql, $_POST['rid'] ) ) > 0 ){ //update
+              $data = array( 'form_value'	=> $files );
+              $where = array(
+                'request_id'	=> $_POST['rid'],
+                'form_field'	=> '_result_files',
+              );
+              $where_format = array(
+                'request_id'	=> '%d',
+                'form_field'	=> '%s',
+              );
+              $wpdb->update( $wpdb->prefix . 'fantastic_analysis_requests_info', $data, $where, '%s', $where_format );
+            }
+            else{ //new
+              $data = array(
+                'request_id'	=> $_POST['rid'],
+                'form_field'	=> '_result_files',
+                'form_value'	=> $files
+              );
+              $where = array(
+                'request_id'	=> '%d',
+                'form_field'	=> '%s',
+                'form_value'	=> '%s'
+              );
+              $wpdb->insert( $wpdb->prefix . 'fantastic_analysis_requests_info', $data, $where );
+            }
         }
         }
 
 
         // replace filename reference by the final file
         // replace filename reference by the final file