php - Using require once or include to upload multiple scripts in a form -


so have php script handles uploading multiple sites. there 3 sites in all, using same class uploading different api array..

below 1 of scripts handles uploading...

class apiupload {    private $data;     public function __construct( array $data )    {        $this -> data = $data;    }     public function doupload()    {        $ch = curl_init();         if ( is_resource( $ch ) )        {             curl_setopt( $ch, curlopt_url, 'http://example.com/upload_api/' );              curl_setopt( $ch, curlopt_returntransfer, true );              curl_setopt( $ch, curlopt_postfields, $this -> data );              curl_setopt( $ch, curlopt_timeout, 5 );              $data = curl_exec( $ch );              curl_close( $ch );        }         if ( empty( $data ) )        {             $this -> error = 'an unexpected error occured.';              return;        }         return $this -> parse( $data );    }     private function parse( $data )    {        if ( ! ( $json = json_decode( $data, true ) ) or ( json_last_error() ) )        {                                                         $this -> error = 'there issue decoding response.';              return;        }         if ( isset( $json -> error ) )        {             $this -> error = $json -> error;              return;        }         return $json;    }     public function geterror()    {        return $this -> error;    } }  $message = null; if ( $_server[ 'request_method' ] == 'post' ) {      /* initialize upload */      $api = new apiupload([       'name'     => $_post[ 'name' ],       'category' => $_post[ 'category' ],       'hash'   => $_post[ 'apikey' ],       'file'  => '@' . $_post[ 'file' ],       'description'    => $_post[ 'descr' ]      ]);        if ( ! ( $data = $api -> doupload() ) )       {           $message = $api -> geterror();      }        else      {           $message = sprintf( 'your file has been uploaded to: %s', $data[ 'ok' ] );       }       }  ?> 

below above php script, have html script posts values entered php fields....

<div style="color: #ff0000;"><?php echo $message; ?></div>  <form method="post" action="">  <fieldset>  <legend>api example</legend>  <label for="name">name</label> <input type="text" name="name" id="name">  <label for="file">file</label> <select name="file" id="file"> <option value="">select file</option> <?php foreach ( glob( 'files/*.torrent' ) $file ): ?>   <option value="<?php echo $file; ?>"><?php echo basename( $file ); ?></option> <?php endforeach; ?> 

<label for="category">category</label> <select name="category" id="category">   <option value="0">select category</option>   <option value="50">adult xxx</option>   <option value="28">anime</option>   <option value="18">apps</option>   <option value="51">books</option>   <option value="10">games</option>   <option value="52">mobile</option>   <option value="1">movies</option>   <option value="22">music</option>   <option value="33">other</option>   <option value="70">pictures</option>   <option value="113">tv</option>   <option value="71">videos</option>  </select>   <label for="apikey">apikey</label>  <input type="text" name="apikey" id="apikey" value= "">   <label for="description">description</label>  <input type="text" name="descr" id="description" value="default description...">   <input type="submit" value="upload">   </fieldset>   </form> 

so problem have 3 of these php scripts uploading other sites, how can run script can run others @ once...

so eg.. have following

site1.php site2.php site3.php

main script has html form run @ once...

thanks....

you have use multi curl runs multiple request @ once use this.

$urls = array($site1, $site2, $site3); $url_count = count($urls);  $curl_arr = array(); $master = curl_multi_init();  for($i = 0; $i < $url_count; $i++) {     $url =$urls[$i];     $curl_arr[$i] = curl_init($url);     curl_setopt( $curl_arr[$i], curlopt_url, 'http://example.com/upload_api/' );     curl_setopt( $curl_arr[$i], curlopt_returntransfer, true );     curl_setopt( $curl_arr[$i], curlopt_postfields, $this -> data );     curl_setopt( $curl_arr[$i], curlopt_timeout, 5 );     curl_multi_add_handle($master, $curl_arr[$i]); }  {     curl_multi_exec($master,$running); } while($running > 0); 

Comments

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -