I am trying to upload a file in chunks via Dropbox's API for PHP.
This is my code: This gives out the folowing error:
First few chunks are uploaded and then I get this error:-
Fatal error: Uncaught exception 'Dropbox\Exception_NetworkIO' with message 'Erro
r executing HTTP request: Failed to connect to api-content.dropbox.com port 443:
Connection refused' in /home/yashtk1/public_html/dropbox/Dropbox/Curl.php:69
Stack trace:
#0 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(721): Dropbox\Curl->exec
()
#1 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(602): Dropbox\Client->_c
hunkedUpload(Array, '`S\xCDb0\x80`\xA0\xD3\xB7\xEA\x07\xF1\xF7\xB4...')
#2 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(437): Dropbox\Client->ch
unkedUploadContinue('jB2ZQWVyzMQgsX4...', 41943040, '`S\xCDb0\x80`\xA0\xD3\xB7\x
EA\x07\xF1\xF7\xB4...')
#3 /home/yashtk1/public_html/dropbox/Dropbox/RequestUtil.php(278): Dropbox\Clien
t->Dropbox\{closure}()
#4 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(438): Dropbox\RequestUti
l::runWithRetry(3, Object(Closure))
#5 /home/yashtk1/public_html/dropbox/Dropbox/Client.php(381): Dropbox\Client->_u
ploadFileChunked('/ahmd1.zip', Object(Dropbox\WriteMode), Resource i in /home/ya
shtk1/public_html/dropbox/Dropbox/Curl.php on line 69
My script:-
<?php
echo "hi";
set_time_limit(0);
# Include the Dropbox SDK libraries
require_once "Dropbox/autoload.php";
use \Dropbox as dbx;
$appInfo = dbx\AppInfo::loadFromJsonFile("config");
$f = fopen("ahmd1.zip", "rb");
$dbxClient = new dbx\Client("Access code", "PHP-Example/1.0");
$mode = dbx\WriteMode::add();
$chunk = $dbxClient->uploadFileChunked("/ahmd1.zip", $mode, $f);
print_r($chunk);
//uploadFileChunked( string $path, Dropbox\WriteMode $writeMode, resource $inStream, integer|null $numBytes = null, integer|null $chunkSize = null );
fclose($f);
?>
Please can anyone point out the mistake ?
Related
Need pro help
Im trying to send sms to my smpp server using onlinecity/php-smpp lib Master.
Code:
<?php
require_once "smpp/smppclient.class.php";
require_once "smpp/gsmencoder.class.php";
require_once "smpp/sockettransport.class.php";
// Construct transport and client
$transport = new SocketTransport(array("my smpp server ip"),2775);
$transport->setSendTimeout(10000);
//$transport->setRecvTimeout(10000);
$smpp = new SmppClient($transport);
$smpp->debug = true;
$transport->debug = true;
// Open the connection
$transport->open();
$smpp->bindTransmitter("test user", "test pass");
// Optional connection specific overrides
//SmppClient::$sms_null_terminate_octetstrings = false;
//SmppClient::$csms_method = SmppClient::CSMS_PAYLOAD;
//SmppClient::$sms_registered_delivery_flag = SMPP::REG_DELIVERY_SMSC_BOTH;
// Prepare message
$message = 'Hello world bla bla';
$encodedMessage = GsmEncoder::utf8_to_gsm0338($message);
$from = new SmppAddress('SMPP Test',SMPP::TON_ALPHANUMERIC);
$to = new SmppAddress(4512345678,SMPP::TON_INTERNATIONAL,SMPP::NPI_E164);
// Send
$messageID = $smpp->sendSMS($from,$to,$encodedMessage);
// Close connection
$smpp->close();
?>
Browser response:
Fatal error: Uncaught SmppException: Failed to read reply to command: 0x4 in /home1/myproject/ems.myproject.com/smpp/smppclient.class.php:620
Stack trace:
#0 /home1/myproject/ems.myproject.com/smpp/smppclient.class.php(392): SmppClient->sendCommand(4, '\x00\x05\x00SMPP Test\x00\x01\x01...')
#1 /home1/myproject/ems.myproject.com/smpp/smppclient.class.php(340): SmppClient->submit_sm(Object(SmppAddress), Object(SmppAddress), 'Hello Voz bla b...', NULL, 0)
#2 /home1/myproject/ems.myproject.com/send_sms.php(35): SmppClient->sendSMS(Object(SmppAddress), Object(SmppAddress), 'Hello world bla b...')
#3 {main}
thrown in /home1/myproject/ems.myproject.com/smpp/smppclient.class.php on line 620
smppclient.class.php:
614 protected function sendCommand($id, $pduBody)
615 {
616 if (!$this->transport->isOpen()) return false;
617 $pdu = new SmppPdu($id, 0, $this->sequence_number, $pduBody);
618 $this->sendPDU($pdu);
619 $response=$this->readPDU_resp($this->sequence_number, $pdu->id);
620 if ($response === false) throw new SmppException('Failed to read reply to command: 0x'.dechex($id));
621
622 if ($response->status != SMPP::ESME_ROK) throw new SmppException(SMPP::getStatusMessage($response->status), $response->status);
623
624 $this->sequence_number++;
625
626 // Reached max sequence number, spec does not state what happens now, so we re-connect
627 if ($this->sequence_number >= 0x7FFFFFFF) {
628 $this->reconnect();
629 }
630
631 return $response;
Note:
PHP 7.4 on Apache
Anyone please help to identify what im doing wrong.
*** Please advice if there any better updated lib for php/smpp
I am trying to the status of urls which are stored in a text file
in my code i have:
$filestatus = file("urlsmartins_status.txt");
foreach ($filestatus as $filestate){
$filestatusurl = (file_get_contents("$filestate"));
$filestatusurlxml = new SimpleXMLElement ($filestatusurl);
print_r ($filestatusurlxml);
}
in the urlsmartin_status.txt i have 5 urls written
http://172.27.73.5:8080/api/service/
http://172.27.73.6:8080/api/service/
http://172.27.73.7:8080/api/service/
http://172.27.73.8:8080/api/service/
But when i execute the code i have the following result
PHP Warning: file_get_contents(http://172.27.73.5:8080/api/service/
): failed to open stream: HTTP request failed! HTTP/1.1 404 OK
PHP Fatal error: Uncaught exception 'Exception' with message 'String could not be parsed as XML' in ...
Stack trace:
#0 /opt/rh/httpd24/root/var/www/html/pub/martin.php(56): SimpleXMLElement->__construct('')
#1 {main}
thrown in /opt/rh/httpd24/root/var/www/html/pub/martin.php on line 56
What am i missing here?
Thanks
the problem here is that the lines in your file are not "XML", hence SimpleXMLElement cannot be instantiated.
I get the same error like this:
I managed to fix it via
$filedata = file_get_contents('urlsmartins_status.txt');
$urls = explode("\n", trim($filedata));
foreach($urls as $key => $url) {
$filestatusurl = file_get_contents("$url");
$filestatusurlxml = new SimpleXMLElement ($filestatusurl);
print_r ($filestatusurlxml);
This is my first attempt using Dropbox API and I'm just following the "Hello World" from PHP SDK. Upload methods is working fine, but download:
$app = new DropboxApp("...", "...", "...");
$dropbox = new Dropbox($app);
$file = $dropbox->download("/image.png", '/image.png');
Return this warning:
Warning: curl_exec(): Could not call the CURLOPT_WRITEFUNCTION in
/srv/www/website/public_html/dropbox/vendor/guzzlehttp/guzzle/src/Handler/CurlHandler.php
on line 40
Fatal error: Uncaught RuntimeException: Unable to open /image.png
using mode w+: fopen(/image.png): failed to open stream: Permission
denied in
/srv/www/website/public_html/dropbox/vendor/guzzlehttp/psr7/src/functions.php:299
Stack trace: #0 [internal function]: GuzzleHttp\Psr7{closure}(2,
'fopen(/unifeal-...', '/srv/www/website/...', 307, Array) #1
/srv/www/website/public_html/dropbox/vendor/guzzlehttp/psr7/src/functions.php(307):
fopen('/image.p...', 'w+') #2
/srv/www/website/public_html/dropbox/vendor/guzzlehttp/psr7/src/LazyOpenStream.php(37):
GuzzleHttp\Psr7\try_fopen('/image.p...', 'w+') #3
/srv/www/website/public_html/dropbox/vendor/guzzlehttp/psr7/src/StreamDecoratorTrait.php(31): GuzzleHttp\Psr7\LazyOpenStream->createStream() #4
/srv/www/website/public_html/dropbox/vendor/guzzlehttp/psr7/src/StreamDecoratorTrait.php(136):
GuzzleHttp\Psr7\LazyOpenStream->__get('stream') #5
/srv/www/website/public_html/dropbox/vendor/guzzlehttp/guzzle/src/Handler/CurlFactory.php(380):
GuzzleHttp\Psr7\LazyOpenStream-> in
/srv/www/website/public_html/dropbox/vendor/guzzlehttp/psr7/src/functions.php
on line 299
I'm testing using Vagrant.
UPDATE
I can confirm that is not a permission issue because download works using this script:
$file = $dropbox->download("/image.png");
$contents = $file->getContents();
file_put_contents(__DIR__ . "/image.png", $contents);
$metadata = $file->getMetadata();
But not using the recommended way.
i m using php soapclent, other calls are working good with this URL.here is the snap of the request to be passed.
not getting what is the problem ?
( ! ) Fatal error: Uncaught SoapFault exception: [SOAP-ENV:Client]
true in C:\wamp\www\ginger\createEditProfile.php:8 Stack trace: #0
C:\wamp\www\ginger\createEditProfile.php(8):
SoapClient->__soapCall('createEditProfi...', Array) #1 {main} thrown
in C:\wamp\www\ginger\createEditProfile.php on line 8
error_reporting(E_ALL);
$sc = new SoapClient("http://###.###.##.##/GingerIBE/services/consolidatedServicesBean.wsdl?wsdl", array('trace' => 1));
$params =array('targetProfile'=>array('loginId'=>'bhav1234','password'=>'test123','preferredHotel'=>'', 'customerId'=>'','firstName'=>'Bhavina','lastName'=>'Prajapati','customerType'=>'1','customerAccountGroup'=>'SH01','gender'=>'Female','dateOfBirth'=>'1987-11-01','emailId'=>'testing.abc#gmail.com','mobileNumber'=>'8866853905','phoneNumber'=>'8866853906','faxNumber'=>'8866853901','preferredModeOfContact'=>'','addressLine1'=>'some address line 1','addressLine2'=>'some address line 2','pinNumber'=>'','city'=>'Bangalore','state'=>'Karnataka','country'=>'India'));
$result = $sc->__soapCall('createEditProfile', array('parameters' => $params));
echo "<pre>";
print_r($result);
echo($sc->__getLastRequest());
I've got a working website, which uses youtube api. Everything was fine but today I noticed I get error while using this api:
Fatal error: Uncaught exception 'Zend_Gdata_App_HttpException' with message 'Expected response code 200, got 403 <?xml version='1.0' encoding='UTF-8'?><errors><error><domain>yt:quota</domain><code>too_many_recent_calls</code></error></errors>' in /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php:700 Stack trace: #0 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata.php(221): Zend_Gdata_App->performHttpRequest('GET', 'http://gdata.yo...', Array, NULL, NULL, NULL) #1 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php(861): Zend_Gdata->performHttpRequest('GET', 'http://gdata.yo...', Array) #2 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php(754): Zend_Gdata_App->get('http://gdata.yo...', NULL) #3 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php(205): Zend_Gdata_App->importUrl('http://gdata.yo...', 'Zend_Gdata_YouT...', NULL) #4 /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata.php( in /root/public_html/grabandrun.com/public/ZendGdata/library/Zend/Gdata/App.php on line 700
my code looks somehow like this:
require_once 'Zend/Loader.php';
Zend_Loader::loadClass('Zend_Gdata_YouTube');
Zend_Loader::loadClass('Zend_Uri_Http');
$yt = new Zend_Gdata_YouTube();
$query = $yt->newVideoQuery();
$query->setQuery($searchTerms);
$query->setStartIndex($index2);
$query->setMaxResults(10);
$query->setOrderBy($order);
$videoFeed = $yt->getVideoFeed($query);
foreach ($videoFeed as $videoEntry) {
$videoThumbnails = $videoEntry->mediaGroup->thumbnail[0]->url;
$title = $videoEntry->mediaGroup->title;
$vidId = $videoEntry->getVideoId();
$vidDescription = $videoEntry->mediaGroup->description;
$duration = $videoEntry->mediaGroup->duration->seconds;
$rating = round($videoEntry->rating->average,1)." out of 5";
echo "info...";
}
Funny thing is that it sometime works and sometime does not... I don't really know why, any help appreciated, thanks.
As stated in comments, I just had to limit the access and lower the calls. Thanks Slava.