Last active
March 3, 2016 09:34
-
-
Save faisalahsan/f2a426b709e259142525 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.