Skip to content

Instantly share code, notes, and snippets.

@faisalahsan
Last active March 3, 2016 09:34
Show Gist options
  • Save faisalahsan/f2a426b709e259142525 to your computer and use it in GitHub Desktop.
Save faisalahsan/f2a426b709e259142525 to your computer and use it in GitHub Desktop.
<?php
require_once 'PHPToolkit/NetSuiteService.php';
$service = new NetSuiteService();
$uploadFile = new File();
$attachFrom = '_computer'; // or $attachFrom = _web
$path = 'imageFromComputer.jpg'; // or for image url i.e. $path = 'http://www.qspectrum.com/wp-content/uploads/2015/08/dummy-profile-pic-male.jpg';
$extentionType = pathinfo($path, PATHINFO_EXTENSION);
$data = file_get_contents($path);
$uploadFile->name = 'ImageName'.strtolower($extentionType);
if ( $attachFrom == '_computer' ){
$base64 = 'data:image/' . $extentionType . ';base64,' . base64_encode($data);
$base64Image = $base64;
$uploadFile->content = $base64Image;
}
$uploadFile->attachFrom = $attachFrom;
$folderRef = new RecordRef();
$folderRef->internalId = 19;
$uploadFile->folder = $folderRef;
$uploadFile->fileType = '_IMAGE';
$uploadFile->mediaTypeName = strtoupper($extentionType).' Image';
$request = new AddRequest();
$request->record = $uploadFile;
$addResponse = $service->add($request);
if (!$addResponse->writeResponse->status->isSuccess) {
echo "ADD ERROR";
echo '<pre>';
print_r($addResponse);
} else {
echo "ADD SUCCESS, internalId " . $addResponse->writeResponse->baseRef->internalId;
echo '<pre>';
print_r($addResponse);
}
Copy link

ghost commented Jan 22, 2016

Certain types of resources can be quite large, requiring excessive processing on GitHub.

@waqas385
Copy link

You can improve your if/else condtional code by extracting common piece of code from it. Overall its a good effort and helpful for newbie to use your code to save image.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment