• הרשמה
    • התחברות
    • חיפוש
    • דף הבית
    • אינדקס קישורים
    • פוסטים אחרונים
    • קבלת התראות מהדפדפן
    • משתמשים
    • חיפוש בהגדרות המתקדמות
    • חיפוש גוגל בפורום
    • ניהול המערכת
    • ניהול המערכת - שרת private

    נפתר העלאת קובץ שמע לנתיב מוגדר מראש

    פורום מפתחים API
    3
    7
    276
    טוען פוסטים נוספים
    • מהישן לחדש
    • מהחדש לישן
    • הכי הרבה הצבעות
    תגובה
    • הגיבו כנושא
    התחברו בכדי לפרסם תגובה
    נושא זה נמחק. רק משתמשים עם הרשאות מתאימות יוכלו לצפות בו.
    • מ
      מנסה נערך לאחרונה על ידי מנסה

      עריכה: תכלס יש כאן את הדבר הזה

      איך מגדירים למחלקה קובץ שמע שהועלה בטופס?

      ניסיתי להכניס עם המחלקה של @מאזין-נלהב קובץ שמע ע"י טופס שמתחבר לPHP אבל הוא כותב שגיאה קריטית

      Fatal error: Uncaught Error: Class "connecting_to_yemot_api" not found in C:\xampp1\htdocs\ngkvkroys.php:42 Stack trace: #0 {main} thrown in C:\xampp1\htdocs\ngkvkroys.php on line 42
      

      את הקובץ אני מצליח להעלות דרך טופס [חיקוי של הקובץ שנמצא בהעלאת קבצים בAPI]
      ולקבל את פרטיו

      אבל אני לא מצליח להגדיר למחלקה להעלות אותו

      [קבצי טקסט אני מצליח, ושיניתי כמובן את 0 ל1 שיבצע המרה]

      תודה

      זה הקובץ המלא
      חלק ראשון קבלת הקובץ ופירוק החלקים שלו למשתנים
      חלק שני המחלקה
      חלק שלישי הטופס HTML

      <?php
      
      if(isset($_POST["submit"]))
      {
      	
      	if(isset($_FILES['upload'])){
      
      $file1 = $_FILES['upload'];
      print_r ($file1);
      	}
      if(isset($_FILES['upload'])){ //האם בכלל נשלח הקובץ באמצעות הטופס
      
      	     // נאחסן כל אחד מהערכים לתוך משתנה
      
      	     //זה השם המקורי שנרצה לשמור עליו גם אחרי ההעברה
      
      	     $fname  = $_FILES['upload']['name'];
      
      	     //סוג הקובץ יכול לשמש להגבלת סוגי הקבצים שאנחנו מתירים להעלות
      
      	     $ftype  = $_FILES['upload']['type'];
      
      	     // מכאן נצטרך להעביר את הקובץ לתיקייה הקבועה
      
      	     $ftmp   = $_FILES['upload']['tmp_name'];
      
      	     // קוד שגיאה
      
      	     $ferror = $_FILES['upload']['error'];
      
      	     // גודלו של הקובץ בבייטים
      
      	     $fsize  = $_FILES['upload']['size'];
      
      	}
      	
      
      $mahahrechet='0777777777';
      $pas='123456';
      
      //זיהוי מערכת להעלות את הקובץ
      $con = new connecting_to_yemot_api($mahahrechet, $pas);
      //יוצר קובץ להעלאה
      $File = new oFile('$fname' , 'text/plain' , $ftmp);
      //מיקום הקובץ
      $body = array
      (
      'path' => 'ivr2:/1/$fname  ',
      'convertAudio' => 1,
      'fileUpload' => $File
      );
      //הפעלת העלאת הקובץ
      $a = $con -> connecting('UploadFile', $body);
      
      $b = $a->responseStatus; 
      
      
       
      //הדפס תשובה
      print_r($a);
      
      //המחלקה
      class BodyPost
      {
      // part "multipart/form-data"
      public static function PartPost($name, $val)
      {
      $body = 'Content-Disposition: form-data; name="' . $name . '"';
      // check instance of oFile
      if($val instanceof oFile)
      {
      $file = $val->Name();
      $mime = $val->Mime();
      $cont = $val->Content();
      
      $body .= '; filename="' . $file . '"' . "\r\n";
      $body .= 'Content-Type: ' . $mime ."\r\n\r\n";
      $body .= $cont."\r\n";
      } else $body .= "\r\n\r\n".$val."\r\n";
      return $body;
      }
      
      public static function Get(array $post, $delimiter = '-------------0123456789')
      {
      if(is_array($post) && !empty($post))
      {
      $bool = true;
      //foreach($post as $val) if($val instanceof oFile) {$bool = true; break; };
      if($bool)
      {
      $ret = '';
      foreach($post as $name=>$val)
      $ret .= '--' . $delimiter. "\r\n". self::PartPost($name, $val);
      $ret .= "--" . $delimiter . "--\r\n";
      } else $ret = http_build_query($post);
      } else throw new \Exception('Error input param!');
      return $ret;
      }
      }
      
      class oFile
      {
      private $name;
      private $mime;
      private $content;
      
      public function __construct($name, $mime=null, $content=null)
      {
      if(is_null($content))
      {
      $info = pathinfo($name);
      // check is exist and readable file
      if(!empty($info['basename']) && is_readable($name))
      {
      $this->name = $info['basename'];
      // get MIME
      $this->mime = mime_content_type($name);
      // load file
      $content = file_get_contents($name);
      if($content!==false)
      {
      $this->content = $content;
      }
      else
      {
      throw new Exception('Don`t get content - "'.$name.'"');
      }
      }
      else
      {
      throw new Exception('Error param');
      }
      }
      else
      {
      $this->name = $name;
      if(is_null($mime)) $mime = mime_content_type($name);
      $this->mime = $mime;
      $this->content = $content;
      };
      }
      
      public function Name() { return $this->name; }
      
      public function Mime() { return $this->mime; }
      
      public function Content() { return $this->content; }
      
      }
      
      class connecting_to_yemot_api
      {
      public $token;
      
      const URL = 'https://www.call2all.co.il/ym/api/';
      
      public function __construct($user_name, $password)
      {
      $body = array('username' => $user_name, 'password' => $password);
      
      $body = http_build_query($body);
      
      $opts = array('http' => array(
      
      'method' => 'POST',
      
      'header' => "Content-Type: application/x-www-form-urlencoded",
      
      'content' => $body,
      
      'follow_location' => false) );
      
      $context = stream_context_create($opts);
      
      $url = self::URL.'Login';
      
      $result = file_get_contents($url, FALSE, $context);
      
      $result = json_decode($result);
      
      if($result -> responseStatus == 'OK')
      {
      $this -> token = $result -> token;
      
      return TRUE;
      }
      else
      {
      throw new Exception('שם המשתמש או הסיסמא של המערכת שגויים');
      }
      }
      
      public function __destruct()
      {
      $this -> connecting('Logout');
      }
      
      public function connecting($action, $body = array())
      {
      $delimiter = '----'.uniqid();
      
      $body['token'] = $this -> token;
      
      $body = BodyPost::Get($body, $delimiter);
      
      $opts = array('http' =>
      array(
      'method' => 'POST',
      'header' => 'Content-Type: multipart/form-data; boundary='.$delimiter,
      'content' => $body,
      'follow_location' => false
      )
      );
      $context = stream_context_create($opts);
      
      $url = self::URL.$action;
      
      $result = file_get_contents($url, FALSE, $context);
      
      $headers = $this -> parseHeaders($http_response_header);
      
      if($headers['Content-Type'][0] == 'application/json')
      {
      return json_decode($result);
      }
      else
      {
      return $result;
      }
      }
      
      private function parseHeaders($headers)
      {
      // פונקציה שמקבלת מערך של שורות הכותרות
      // הפונקציה מפרקת את קבצי הקוקי לתת-מערך נפרד
      
      
      // מערך הכותרות
      $head = array();
      
      foreach( $headers as $k=>$v )
      {
      $t = explode( ':', $v, 2 );
      
      if( isset( $t[1] ) )
      {
      if($t[0] == 'Set-Cookie')
      {
      $CookiesArr = array();
      
      $cookies = explode( ';', $t[1]);
      
      foreach($cookies as $cookie)
      {
      $c = explode( '=', $cookie);
      
      if( isset( $c[1] ) )
      {
      $CookiesArr[ trim($c[0]) ] = trim( $c[1] );
      }
      else
      {
      $CookiesArr[] = trim( $c[0] );
      }
      }
      
      $head[ trim($t[0]) ] = $CookiesArr;
      }
      elseif($t[0] == 'Content-Type')
      {
      $arr = array();
      
      $children = explode( ';', $t[1]);
      
      foreach($children as $child)
      {
      $c = explode( '=', $child);
      
      if( isset( $c[1] ) )
      {
      $arr[ trim($c[0]) ] = trim( $c[1] );
      }
      else
      {
      $arr[] = trim( $c[0] );
      }
      }
      
      $head[ trim($t[0]) ] = $arr;
      }
      else
      {
      $head[ trim($t[0]) ] = trim( $t[1] );
      }
      }
      else
      {
      $head[] = $v;
      if( preg_match( "#HTTP/[0-9\.]+\s+([0-9]+)#",$v, $out ) )
      {
      $head['reponse_code'] = intval($out[1]);
      }
      }
      }
      return $head;
      }
      }
      
      	 exit;
      }
      
      ?>
      <html>
      <body>
          <p>B.H.</p>
          <form action="" method="POST" enctype="multipart/form-data" target="_blank">
      
              <p>
                  <input type="file" name="upload" accept="audion/*">
              </p>
            
              <p>
                  <input type="submit" name="submit">
              </p>
          </form>
      
      
      </body>
      
      </html>
      
      
      א תגובה 1 תגובה אחרונה תגובה ציטוט 1
      • א
        איש ימיני @מנסה נערך לאחרונה על ידי

        @מנסה
        יש לי דבר דומה ועובד מצוין.
        מצורף הקוד המטפל בהעלאה, עובד עם המחלקה.

                    $con = new connecting_to_yemot_api('0773137770', '1234',false);
                    $File = new oFile($_REQUEST['name'].'.wav', 'text/plain', file_get_contents($_FILES['file'][tmp_name]));
        
                    $a = $con -> connecting('UploadFile',[
                        'path' => 'ivr2:1/$_REQUEST['name'].'.wav',
                        'convertAudio' => 1,
                        'fileUpload' => $File
                    ]);
        
        מ תגובה 1 תגובה אחרונה תגובה ציטוט 1
        • מ
          מנסה @איש ימיני נערך לאחרונה על ידי

          @איש-ימיני

          עדיין מחזיר אותה שגיאה

          אגב, מדוע לא שמת גרש בתחילה ובסוף ל file_get_contents($_FILES['file'][tmp_name]));?

          תודה רבה

          L תגובה 1 תגובה אחרונה תגובה ציטוט 1
          • L
            Liy @מנסה נערך לאחרונה על ידי

            @מנסה אמר בהעלאת קובץ שמע לנתיב מוגדר מראש:

            @איש-ימיני

            עדיין מחזיר אותה שגיאה

            אגב, מדוע לא שמת גרש בתחילה ובסוף ל file_get_contents($_FILES['file'][tmp_name]));?

            תודה רבה

            אתה מנסה לשלוח מהlocalhost?

            מ תגובה 1 תגובה אחרונה תגובה ציטוט 0
            • מ
              מנסה @Liy נערך לאחרונה על ידי מנסה

              @liy

              כן

              [בדקתי בPHP.INI הגודל הוא עד 40 מגה בייט, אם לזה התכוונת]

              תודה

              L תגובה 1 תגובה אחרונה תגובה ציטוט 1
              • הנושא סומן כשאלה  מ מנסה 
              • L
                Liy @מנסה נערך לאחרונה על ידי

                @מנסה אמר בהעלאת קובץ שמע לנתיב מוגדר מראש:

                כן

                אז שתדע שכשאשר שולחים בקשה מlocalhost לשרת חיצוני הבקשה תכשל...

                מ תגובה 1 תגובה אחרונה תגובה ציטוט 0
                • מ
                  מנסה @Liy נערך לאחרונה על ידי מנסה

                  @liy

                  אבל אני מצליח להעלות קבצי טקסט ולהוריד גם אם המחלקה וגם אם file_get_contents

                  תודה

                  וגם בשרת אמיתי [הוסטינגר לא חינמי] זה לא עולה

                  אני מבין שיש לי טעות, השאלה מהי

                  תודה רבה

                  תגובה 1 תגובה אחרונה תגובה ציטוט 1
                  • הנושא סומן כנפתר  מ מנסה 
                  • פוסט ראשון
                    פוסט אחרון