Class 'google\appengine\CreateUploadURLRequest' not found - php

i am using google cloud using CORE PHP to upload file using simple HTML Form But i am stuck on CloudStorageTools Class
it throws continuous following error
Fatal error: Class
'google\appengine\api\cloud_storage\CloudStorageTools' not found
For Solve that i Included
include_once __DIR__ . '/vendor/autoload.php';
//Include class
require_once "google/appengine/api/cloud_storage/CloudStorageTools.php";
use google\appengine\api\cloud_storage\CloudStorageTools;
But than it throws second error. where am i going wrong in google cloud setup.
My full code looks like
$bucket = 'bucketname';
$root_path = 'gs://' . $bucket . '/';
$options = ['gs_bucket_name' => $bucket];
$upload_url = CloudStorageTools::createUploadUrl('/upload/handler', $options);
$_url = '';
if(isset($_POST['submit']))
{
if(isset($_FILES['userfile']))
{
$name = $_FILES['userfile']['name'];
$file_size =$_FILES['userfile']['size'];
$file_tmp =$_FILES['userfile']['tmp_name'];
$original = $root_path .$name;
move_uploaded_file($file_tmp, $original);
$_url=CloudStorageTools::getImageServingUrl($original);
}
}

Related

upload videos file with jwplatform [PHP]

so here is my problem:
I want to use jwplatform-php to upload my video files.
here is my php script: (this is more or less the sample script provided)
<?php
use Jwplayer\JwplatformClient;
header_remove( 'X-Powered-By' );
chdir(dirname(__DIR__));
require 'vendor' . DIRECTORY_SEPARATOR . 'autoload.php';
$secret = "XXXXXXXXXXXXXXXXXXX";
$site_id = "XXXXX";
$jwplatform_api = new JwplatformClient($secret);
$target_file = "test.mp4";
$params = [];
$params['metadata'] = [];
$params['metadata']['title'] = 'PHP API Test Upload';
$params['metadata']['description'] = 'Video description here';
$params['upload'] = [];
$params['upload']['method'] = 'direct';
// Create the example media
$create_response = json_encode($jwplatform_api->Media->create($site_id, $params));
print_r($create_response);
print("\n");
$decoded = json_decode(json_decode(trim($create_response), true), true);
$upload_link = $decoded['upload_link'];
// Upload the media file
$upload_response = $jwplatform_api->Media->upload($target_file, $upload_link);
print_r($upload_response);
print("\n");
And so the error occurs at $create_response he return false.
I think the problem is $target_file = "test.mp4"; that he can't solve even by putting the relative path $target_file = dirname(__FILE__) . DIRECTORY_SEPARATOR ."test.mp4"; he returns to me false.
I don't know what to do and in addition the doc jwplatform-php is almost non-existent
I thank you already for all the help provided and sorry for my approximate English...

HTML2PDF 504 Gateway Timeout

I am trying to convert HTML 2 PDF with this library and its converting fine as per my expectations.
However, When I convert with more data, its giving me an error saying 504 Gateway Timeout. Here is the error screenshot what I am getting.
In local server its working fine. I have the same server in my local and my live (Linux). The only problem is I am getting when I try to produce PDF with long data on live server.
I researched and found out that to increase php execution time and other settings. Hence I try to put below code in my .php file.
ini_set('max_execution_time', 60000);
ini_set('post_max_size','128M');
ini_set('upload_max_filesize','128M');
I even try to set max_execution_time to 0 and -1 but yet its not working for me. After setting this values, I even printed the updated values with phpinfo(), the values are overwriting but I am having the same 502 Gateway timeout error. Here is small chunk of code just in case you want to see.
<?php
ini_set('max_execution_time', 60000);
ini_set('post_max_size','20M');
ini_set('upload_max_filesize','8M');
require_once dirname(__FILE__) . '/vendor/autoload.php';
require_once dirname(__FILE__) . '/templateInfo.php';
use Spipu\Html2Pdf\Html2Pdf;
use Spipu\Html2Pdf\Exception\Html2PdfException;
use Spipu\Html2Pdf\Exception\ExceptionFormatter;
use technobrave\brochuresettings\Models\Brochuresettings as BS;
use Technobrave\Transactions\Models\Transactions as TR;
use Technobrave\Offices\Models\Offices;
use technobrave\themesettings\Models\ThemeSetting as TS;
use Technobrave\Team\Models\Team;
class generateTemplate {
public $theme = "";
public $theme_settings = array();
public function __construct($templateId, $resolution , $theme ,$pdf_sections = array(),$openFile = false, $finalPdfFile = null) {
$this->getBrochureTransactionData = BS::first();
$this->getPdfSection = $pdf_sections;
$this->theme_settings = TS::first();
$this->theme = $theme;
$this->baseUrl = url(Config::get('cms'));
$this->teamPageName = $this->baseUrl . '/our-team';
$this->capabilitiesPageName = $this->baseUrl . '/capabilities';
$this->getFooterText = $this->getFooterText();
$getTeamId = (isset($_GET['teamId']) && !empty($_GET['teamId'])) ? $_GET['teamId'] : "";
$this->uniquePath = __DIR__ . DIRECTORY_SEPARATOR . 'images' . DIRECTORY_SEPARATOR;
$templatePath = __DIR__ . DIRECTORY_SEPARATOR . 'regency_template' . DIRECTORY_SEPARATOR . $getTeamId . DIRECTORY_SEPARATOR . $templateId . '.php';
$templateInfoText = new templateInfo($templateId, $this->uniquePath, $getTeamId);
$this->customImagePath = $this->uniquePath;
foreach ($templateInfoText->defaultValues as $key => $value) {
$this->{$key} = $value;
}
$template = file_get_contents($templatePath);
try
{
$html2pdf = new Html2Pdf('L','A4', 'en', true, 'UTF-8', array(0, 0, 0, 0));
$html2pdf->Addfont('perpetua');
$html2pdf->Addfont('montserratbold');
$html2pdf->Addfont('montserratmedium');
$html2pdf->Addfont('montserratregular');
$html2pdf->Addfont('montserratsembold');
$html2pdf->Addfont('montserratitalic');
$html2pdf->writeHTML($template, false);
$html2pdf->Output('regency_corporate_brochure.pdf', 'D');
} catch (Html2PdfException $e) {
$formatter = new ExceptionFormater($e);
echo $formatter->getHtmlMessage();
}
}
}
I tried to preview how my HTML is generating and its generating without any error.
$html2pdf->writeHTML($template, true);
So basically I am facing server issue here as per my understanding so far.
Can someone guide me what should I do from here on to solve this issue.
After a hard debugging I found that my problem was that I was including an external image in the PDF and the server can't reach the server image (server access only trough white-list IP).

Class Not found when autoloading with namespace (no Composer)

I have been checking for answers but with no success. I'm not using composer autoload function.
I'm trying to test some classes, Collections and traits in a index.php.
The problem is when i'm including a namespace, I'have created the _autoload function (No composer) to load a class when needed. If I execute php index.php i'm getting the class not found error.
I have tried the use command, but with no success as well.
It solves when I include each class one by one like this:
include_once __DIR__ . '/Collection.php';
include_once __DIR__ . '/User.php';
include_once __DIR__ . '/Tweet.php';
include_once __DIR__ . '/UserCollection.php';
include_once __DIR__ . '/TweetCollection.php';
Thats my index.php:
<?php
namespace phpexercises\entregableT3;
error_reporting(E_ALL);
ini_set( "display_errors", "on" );
/*
include_once __DIR__ . '/Collection.php';
include_once __DIR__ . '/User.php';
include_once __DIR__ . '/Tweet.php';
include_once __DIR__ . '/UserCollection.php';
include_once __DIR__ . '/TweetCollection.php';
*/
use phpexercises\entregableT3\User;
function __autoload($classname){
require __DIR__ . "/" . $classname . ".php";
}
//UserCollection pruebas
$alex = new User();
$jumbo = new User();
$users = new UserCollection();
$alex->phone = "682383";
$alex->email = "alex#example.com";
$alex->city = "BCN";
$alex->gender = "Male";
$jumbo->phone = "54534535";
$jumbo->email = "jumbo#example.com";
$jumbo->city = "elche";
$jumbo->gender = "Male";
$users->add($alex);
$users->add($jumbo);
print_r($users->findByEmail("alex#example.com"));
print_r($users->findByGender("Female"));
//Tweet Collection pruebas
$tweet = new Tweet();
$tweet->email = "alex#example.com";
$tweet->text = "This is a tweet";
$tweet->date = date("D:M:Y");
$tweet1 = new Tweet();
$tweet1->email = "alex#example.com";
$tweet1->text = "This is a tweet";
$tweet1->date = date("D:M:Y");
When I uncomment the requires, everything works fine, but it is not the way to load all classes...Any idea for this behaviour? How should I load the classes at same time?
Thanks

file rename() function works but also throws error

I'm trying to rename a file, when i call rename() function the file get gets renamed but it still gives me error "The filename uploads/09-12-2015.xls is not readable"
date_default_timezone_set('America/Chicago');
/** Include path **/
set_include_path(get_include_path() . PATH_SEPARATOR . '../../../Classes/');
include 'lib/Classes/PHPExcel/IOFactory.php';
/** PHPExcel_IOFactory */
include 'connect.php';
if (isset($_POST['config']))
{
$hotelName = $_POST['shortname'];
$reportDate = $_POST['reportDate'];
$dateCol = $_POST['dateCol'];
$dateRow = $_POST['dateRow'];
$soldCol = $_POST['soldCol'];
$revCol = $_POST['revCol'];
$todayDate = date('m-d-Y');
rename("uploads/$todayDate.xls","uploads/$reportDate.xls");
echo "done";
//$objPHPExcel = PHPExcel_IOFactory::load($inputFileName);
//$sheetData = $objPHPExcel->getActiveSheet()->toArray(null,true,true,true);
}

PHP autoload oddity

function __autoload($class_name) {
echo("Attempting autoload ");
if (substr($class_name, -6) == "Mapper") {
$file = 'mappers/'.$class_name.'.php';
echo "Will autoload $file ";
include_once($file);
}
}
__autoload("UserMapper");
$user = new UserMapper($adapter);
die("done");
Result:
Attempting autoload Will autoload mappers/UserMapper.php done
function __autoload($class_name) {
echo("Attempting autoload ");
if (substr($class_name, -6) == "Mapper") {
$file = 'mappers/'.$class_name.'.php';
echo "Will autoload $file ";
include_once($file);
}
}
//__autoload("UserMapper");
$user = new UserMapper($adapter);
die("done");
(I just commented out the manual call to __autoload()...)
Result:
Fatal error: Class 'UserMapper' not found in C:\Program Files\EasyPHP-5.3.5.0\www\proj\29letters\login.php on line 13
Any ideas?
And yes, I'm running PHP 5.3.5
Not sure why your example isn't working, as it should be as per the manual.
Have you tried using spl_autoload_register to register the autoloader function?
Have you set a proper include_path? You're using a relative path to include the class's file. Try an absolute path instead.
$dir = __DIR__ . '/../path/to/mappers';
$file = $dir . '/' . $class_name . '.php';
require $file;
or
// do this outside of __autoload
set_include_path(get_include_path() . PATH_SEPARATOR . __DIR__ . '/../path/to/mappers';
// inside __autoload
$file = $class_name . '.php';
require $file;

Categories