Laravel: Base64 Image not Uploading











up vote
0
down vote

favorite












Using Laravel and PHP, I am trying to add a photo to a database. This database only takes base64 images.



I take a given file, verify that it's an image type (png, jpg, etc.) and try to encode it as a base64 image. Then I try to upload it to the database with other details about the object.



However, this isn't working. Instead I am told of a data type mismatch:




SQLSTATE[HY000]: General error: 20018 Implicit conversion from data
type varchar(max) to varbinary(max) is not allowed. Use the CONVERT
function to run this query. [20018] (severity 16)




My code absolutely works when I remove the 'photo' value from the insertion. So I'm wondering what it is that could be the problem with what I'm doing.



See below my laravel controller function.



public function addStudent(Request $request) {
$courses = [1, 2, 3, 4, 5];
$statuses = [1,2,3,4];

$validated = Validator::make($request->all(), [
"submit" => "required",
"student_id" => ["required", "integer", "regex:/^[0-9]+$/"],
"forename" => ["required", "regex: /^[a-zA-Z’'. -]+$/"],
"surname" => ["required", "regex: /^[a-zA-Z’'. -]+$/"],
"course_id" => ["required", Rule::in([1, 2, 3, 4, 5]) ],
"status_id" => ["required", Rule::in([1, 2, 3, 4]) ],
/*Image validation done here: must be of the types below
Since this part passes, I know I am working with an image */
"photo" => "required|image|file:jpeg,png,jpg,gif,svg|max:2048"
]);
$errors = $validated->errors();
if($validated->fails()) {
return redirect()->back()->withInput($request->all())->withErrors($errors);
}
$data = $request->all();

/* Here I try to encode the image as base64 */
if ($request->hasFile("photo")) {
if($request->file("photo")->isValid()) {
$file = $request->file('photo');
$image = base64_encode($file);
$image = base64_encode(file_get_contents($request->file('photo')));
if (!($image)) {
echo "<h3>Image null!</h3>";
}
}
} else {
echo "<h3>Request doesn't have photo</h3>";
}
/*Try to upload values to database, return errors if fail */
try {
$insert =
DB::table('CCEAGpoc.dbo.Student')->insert([
['student_id' => $data['student_id'],
'forename' => $data['forename'],
'surname' => $data['surname'],
'course_id' => $data['course_id'],
'photo' => $image,
'status_id' => $data['status_id']]
]);
return view('success');
} catch (Exception $ex) {
return redirect()->back()->withInput($request->all())->withErrors($errors);
}


For full clarity, my form looks like the following:



<form action="submitAdd" method="post" class="form-inline" enctype="multipart/form-data">
@csrf
...
<div class="form-group">
<label for="photo">Photo: </label>
<input type="file" name="photo" />
</div>

<div class="form-group">
<input type="submit" name="submit" value="Add Student" />
</div>
</form>


I am honestly not sure what it is about the above that is causing the error. If anyone could help, I'd be hugely thankful.










share|improve this question
























  • Could you show the migration that creates the photo field in the database?
    – Adrian Hernandez-Lopez
    Nov 8 at 11:35










  • Storing whole images inside your db is seldom a good idea. Why not uploading your files to your server and then storing the image's path inside your db?
    – Andrea Golin
    Nov 8 at 11:44










  • AndreaGolin I'll bring that up, though whether I can opt for that route isn't my call to make. Thanks for the advice. @AdrianHernandez-Lopez Sure, I'll edit it into the post in a moment.
    – NoStupidQuestions
    Nov 8 at 11:51










  • What is the type of the 'photo' table field?
    – Andrea Golin
    Nov 8 at 11:58










  • @AndreaGolin The type I'm testing with is .png, though it's meant to be valid for any image type as in the validator
    – NoStupidQuestions
    Nov 8 at 12:06















up vote
0
down vote

favorite












Using Laravel and PHP, I am trying to add a photo to a database. This database only takes base64 images.



I take a given file, verify that it's an image type (png, jpg, etc.) and try to encode it as a base64 image. Then I try to upload it to the database with other details about the object.



However, this isn't working. Instead I am told of a data type mismatch:




SQLSTATE[HY000]: General error: 20018 Implicit conversion from data
type varchar(max) to varbinary(max) is not allowed. Use the CONVERT
function to run this query. [20018] (severity 16)




My code absolutely works when I remove the 'photo' value from the insertion. So I'm wondering what it is that could be the problem with what I'm doing.



See below my laravel controller function.



public function addStudent(Request $request) {
$courses = [1, 2, 3, 4, 5];
$statuses = [1,2,3,4];

$validated = Validator::make($request->all(), [
"submit" => "required",
"student_id" => ["required", "integer", "regex:/^[0-9]+$/"],
"forename" => ["required", "regex: /^[a-zA-Z’'. -]+$/"],
"surname" => ["required", "regex: /^[a-zA-Z’'. -]+$/"],
"course_id" => ["required", Rule::in([1, 2, 3, 4, 5]) ],
"status_id" => ["required", Rule::in([1, 2, 3, 4]) ],
/*Image validation done here: must be of the types below
Since this part passes, I know I am working with an image */
"photo" => "required|image|file:jpeg,png,jpg,gif,svg|max:2048"
]);
$errors = $validated->errors();
if($validated->fails()) {
return redirect()->back()->withInput($request->all())->withErrors($errors);
}
$data = $request->all();

/* Here I try to encode the image as base64 */
if ($request->hasFile("photo")) {
if($request->file("photo")->isValid()) {
$file = $request->file('photo');
$image = base64_encode($file);
$image = base64_encode(file_get_contents($request->file('photo')));
if (!($image)) {
echo "<h3>Image null!</h3>";
}
}
} else {
echo "<h3>Request doesn't have photo</h3>";
}
/*Try to upload values to database, return errors if fail */
try {
$insert =
DB::table('CCEAGpoc.dbo.Student')->insert([
['student_id' => $data['student_id'],
'forename' => $data['forename'],
'surname' => $data['surname'],
'course_id' => $data['course_id'],
'photo' => $image,
'status_id' => $data['status_id']]
]);
return view('success');
} catch (Exception $ex) {
return redirect()->back()->withInput($request->all())->withErrors($errors);
}


For full clarity, my form looks like the following:



<form action="submitAdd" method="post" class="form-inline" enctype="multipart/form-data">
@csrf
...
<div class="form-group">
<label for="photo">Photo: </label>
<input type="file" name="photo" />
</div>

<div class="form-group">
<input type="submit" name="submit" value="Add Student" />
</div>
</form>


I am honestly not sure what it is about the above that is causing the error. If anyone could help, I'd be hugely thankful.










share|improve this question
























  • Could you show the migration that creates the photo field in the database?
    – Adrian Hernandez-Lopez
    Nov 8 at 11:35










  • Storing whole images inside your db is seldom a good idea. Why not uploading your files to your server and then storing the image's path inside your db?
    – Andrea Golin
    Nov 8 at 11:44










  • AndreaGolin I'll bring that up, though whether I can opt for that route isn't my call to make. Thanks for the advice. @AdrianHernandez-Lopez Sure, I'll edit it into the post in a moment.
    – NoStupidQuestions
    Nov 8 at 11:51










  • What is the type of the 'photo' table field?
    – Andrea Golin
    Nov 8 at 11:58










  • @AndreaGolin The type I'm testing with is .png, though it's meant to be valid for any image type as in the validator
    – NoStupidQuestions
    Nov 8 at 12:06













up vote
0
down vote

favorite









up vote
0
down vote

favorite











Using Laravel and PHP, I am trying to add a photo to a database. This database only takes base64 images.



I take a given file, verify that it's an image type (png, jpg, etc.) and try to encode it as a base64 image. Then I try to upload it to the database with other details about the object.



However, this isn't working. Instead I am told of a data type mismatch:




SQLSTATE[HY000]: General error: 20018 Implicit conversion from data
type varchar(max) to varbinary(max) is not allowed. Use the CONVERT
function to run this query. [20018] (severity 16)




My code absolutely works when I remove the 'photo' value from the insertion. So I'm wondering what it is that could be the problem with what I'm doing.



See below my laravel controller function.



public function addStudent(Request $request) {
$courses = [1, 2, 3, 4, 5];
$statuses = [1,2,3,4];

$validated = Validator::make($request->all(), [
"submit" => "required",
"student_id" => ["required", "integer", "regex:/^[0-9]+$/"],
"forename" => ["required", "regex: /^[a-zA-Z’'. -]+$/"],
"surname" => ["required", "regex: /^[a-zA-Z’'. -]+$/"],
"course_id" => ["required", Rule::in([1, 2, 3, 4, 5]) ],
"status_id" => ["required", Rule::in([1, 2, 3, 4]) ],
/*Image validation done here: must be of the types below
Since this part passes, I know I am working with an image */
"photo" => "required|image|file:jpeg,png,jpg,gif,svg|max:2048"
]);
$errors = $validated->errors();
if($validated->fails()) {
return redirect()->back()->withInput($request->all())->withErrors($errors);
}
$data = $request->all();

/* Here I try to encode the image as base64 */
if ($request->hasFile("photo")) {
if($request->file("photo")->isValid()) {
$file = $request->file('photo');
$image = base64_encode($file);
$image = base64_encode(file_get_contents($request->file('photo')));
if (!($image)) {
echo "<h3>Image null!</h3>";
}
}
} else {
echo "<h3>Request doesn't have photo</h3>";
}
/*Try to upload values to database, return errors if fail */
try {
$insert =
DB::table('CCEAGpoc.dbo.Student')->insert([
['student_id' => $data['student_id'],
'forename' => $data['forename'],
'surname' => $data['surname'],
'course_id' => $data['course_id'],
'photo' => $image,
'status_id' => $data['status_id']]
]);
return view('success');
} catch (Exception $ex) {
return redirect()->back()->withInput($request->all())->withErrors($errors);
}


For full clarity, my form looks like the following:



<form action="submitAdd" method="post" class="form-inline" enctype="multipart/form-data">
@csrf
...
<div class="form-group">
<label for="photo">Photo: </label>
<input type="file" name="photo" />
</div>

<div class="form-group">
<input type="submit" name="submit" value="Add Student" />
</div>
</form>


I am honestly not sure what it is about the above that is causing the error. If anyone could help, I'd be hugely thankful.










share|improve this question















Using Laravel and PHP, I am trying to add a photo to a database. This database only takes base64 images.



I take a given file, verify that it's an image type (png, jpg, etc.) and try to encode it as a base64 image. Then I try to upload it to the database with other details about the object.



However, this isn't working. Instead I am told of a data type mismatch:




SQLSTATE[HY000]: General error: 20018 Implicit conversion from data
type varchar(max) to varbinary(max) is not allowed. Use the CONVERT
function to run this query. [20018] (severity 16)




My code absolutely works when I remove the 'photo' value from the insertion. So I'm wondering what it is that could be the problem with what I'm doing.



See below my laravel controller function.



public function addStudent(Request $request) {
$courses = [1, 2, 3, 4, 5];
$statuses = [1,2,3,4];

$validated = Validator::make($request->all(), [
"submit" => "required",
"student_id" => ["required", "integer", "regex:/^[0-9]+$/"],
"forename" => ["required", "regex: /^[a-zA-Z’'. -]+$/"],
"surname" => ["required", "regex: /^[a-zA-Z’'. -]+$/"],
"course_id" => ["required", Rule::in([1, 2, 3, 4, 5]) ],
"status_id" => ["required", Rule::in([1, 2, 3, 4]) ],
/*Image validation done here: must be of the types below
Since this part passes, I know I am working with an image */
"photo" => "required|image|file:jpeg,png,jpg,gif,svg|max:2048"
]);
$errors = $validated->errors();
if($validated->fails()) {
return redirect()->back()->withInput($request->all())->withErrors($errors);
}
$data = $request->all();

/* Here I try to encode the image as base64 */
if ($request->hasFile("photo")) {
if($request->file("photo")->isValid()) {
$file = $request->file('photo');
$image = base64_encode($file);
$image = base64_encode(file_get_contents($request->file('photo')));
if (!($image)) {
echo "<h3>Image null!</h3>";
}
}
} else {
echo "<h3>Request doesn't have photo</h3>";
}
/*Try to upload values to database, return errors if fail */
try {
$insert =
DB::table('CCEAGpoc.dbo.Student')->insert([
['student_id' => $data['student_id'],
'forename' => $data['forename'],
'surname' => $data['surname'],
'course_id' => $data['course_id'],
'photo' => $image,
'status_id' => $data['status_id']]
]);
return view('success');
} catch (Exception $ex) {
return redirect()->back()->withInput($request->all())->withErrors($errors);
}


For full clarity, my form looks like the following:



<form action="submitAdd" method="post" class="form-inline" enctype="multipart/form-data">
@csrf
...
<div class="form-group">
<label for="photo">Photo: </label>
<input type="file" name="photo" />
</div>

<div class="form-group">
<input type="submit" name="submit" value="Add Student" />
</div>
</form>


I am honestly not sure what it is about the above that is causing the error. If anyone could help, I'd be hugely thankful.







php laravel






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 8 at 12:17

























asked Nov 8 at 11:29









NoStupidQuestions

63




63












  • Could you show the migration that creates the photo field in the database?
    – Adrian Hernandez-Lopez
    Nov 8 at 11:35










  • Storing whole images inside your db is seldom a good idea. Why not uploading your files to your server and then storing the image's path inside your db?
    – Andrea Golin
    Nov 8 at 11:44










  • AndreaGolin I'll bring that up, though whether I can opt for that route isn't my call to make. Thanks for the advice. @AdrianHernandez-Lopez Sure, I'll edit it into the post in a moment.
    – NoStupidQuestions
    Nov 8 at 11:51










  • What is the type of the 'photo' table field?
    – Andrea Golin
    Nov 8 at 11:58










  • @AndreaGolin The type I'm testing with is .png, though it's meant to be valid for any image type as in the validator
    – NoStupidQuestions
    Nov 8 at 12:06


















  • Could you show the migration that creates the photo field in the database?
    – Adrian Hernandez-Lopez
    Nov 8 at 11:35










  • Storing whole images inside your db is seldom a good idea. Why not uploading your files to your server and then storing the image's path inside your db?
    – Andrea Golin
    Nov 8 at 11:44










  • AndreaGolin I'll bring that up, though whether I can opt for that route isn't my call to make. Thanks for the advice. @AdrianHernandez-Lopez Sure, I'll edit it into the post in a moment.
    – NoStupidQuestions
    Nov 8 at 11:51










  • What is the type of the 'photo' table field?
    – Andrea Golin
    Nov 8 at 11:58










  • @AndreaGolin The type I'm testing with is .png, though it's meant to be valid for any image type as in the validator
    – NoStupidQuestions
    Nov 8 at 12:06
















Could you show the migration that creates the photo field in the database?
– Adrian Hernandez-Lopez
Nov 8 at 11:35




Could you show the migration that creates the photo field in the database?
– Adrian Hernandez-Lopez
Nov 8 at 11:35












Storing whole images inside your db is seldom a good idea. Why not uploading your files to your server and then storing the image's path inside your db?
– Andrea Golin
Nov 8 at 11:44




Storing whole images inside your db is seldom a good idea. Why not uploading your files to your server and then storing the image's path inside your db?
– Andrea Golin
Nov 8 at 11:44












AndreaGolin I'll bring that up, though whether I can opt for that route isn't my call to make. Thanks for the advice. @AdrianHernandez-Lopez Sure, I'll edit it into the post in a moment.
– NoStupidQuestions
Nov 8 at 11:51




AndreaGolin I'll bring that up, though whether I can opt for that route isn't my call to make. Thanks for the advice. @AdrianHernandez-Lopez Sure, I'll edit it into the post in a moment.
– NoStupidQuestions
Nov 8 at 11:51












What is the type of the 'photo' table field?
– Andrea Golin
Nov 8 at 11:58




What is the type of the 'photo' table field?
– Andrea Golin
Nov 8 at 11:58












@AndreaGolin The type I'm testing with is .png, though it's meant to be valid for any image type as in the validator
– NoStupidQuestions
Nov 8 at 12:06




@AndreaGolin The type I'm testing with is .png, though it's meant to be valid for any image type as in the validator
– NoStupidQuestions
Nov 8 at 12:06












1 Answer
1






active

oldest

votes

















up vote
0
down vote



accepted










You must decode your base64 string to binary prior to insert it onto varbinary field, as it will accept only binary data.



The base64 permits a safe binary file transmission, but it is not a valid binary value for mssql varbinary, as it is a string type.



DECLARE @string varchar(20)

SET @string = 'Hello World'

SELECT CONVERT(varbinary, @string)


Also, if your are actually using mssql, you should add mssql tag to your question accordingly, there a lot of people with a lot of mssql skills out there (mssql its not my typical day to day database, my knowledge of it is seriously limitated) that are missing your question.






share|improve this answer























  • Thank you! I'm just looking to write this in PHP/laravel now and I'll confirm if it worked
    – NoStupidQuestions
    Nov 8 at 13:11










  • @NoStupidQuestions maybe give this a try stackoverflow.com/questions/48261495/…
    – Andrea Golin
    Nov 8 at 13:12










  • It's working! My solution was similar to something there: $datastring = file_get_contents($request->file('photo')); $unpack = unpack("H*hex", $datastring); $unpack = '0x'.$unpack['hex']; $answer = DB::raw("CONVERT(VARBINARY(MAX), $unpack)"); Then I use $answer in the insert command down below. Thanks again for your help!
    – NoStupidQuestions
    Nov 8 at 13:41













Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














 

draft saved


draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206843%2flaravel-base64-image-not-uploading%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
0
down vote



accepted










You must decode your base64 string to binary prior to insert it onto varbinary field, as it will accept only binary data.



The base64 permits a safe binary file transmission, but it is not a valid binary value for mssql varbinary, as it is a string type.



DECLARE @string varchar(20)

SET @string = 'Hello World'

SELECT CONVERT(varbinary, @string)


Also, if your are actually using mssql, you should add mssql tag to your question accordingly, there a lot of people with a lot of mssql skills out there (mssql its not my typical day to day database, my knowledge of it is seriously limitated) that are missing your question.






share|improve this answer























  • Thank you! I'm just looking to write this in PHP/laravel now and I'll confirm if it worked
    – NoStupidQuestions
    Nov 8 at 13:11










  • @NoStupidQuestions maybe give this a try stackoverflow.com/questions/48261495/…
    – Andrea Golin
    Nov 8 at 13:12










  • It's working! My solution was similar to something there: $datastring = file_get_contents($request->file('photo')); $unpack = unpack("H*hex", $datastring); $unpack = '0x'.$unpack['hex']; $answer = DB::raw("CONVERT(VARBINARY(MAX), $unpack)"); Then I use $answer in the insert command down below. Thanks again for your help!
    – NoStupidQuestions
    Nov 8 at 13:41

















up vote
0
down vote



accepted










You must decode your base64 string to binary prior to insert it onto varbinary field, as it will accept only binary data.



The base64 permits a safe binary file transmission, but it is not a valid binary value for mssql varbinary, as it is a string type.



DECLARE @string varchar(20)

SET @string = 'Hello World'

SELECT CONVERT(varbinary, @string)


Also, if your are actually using mssql, you should add mssql tag to your question accordingly, there a lot of people with a lot of mssql skills out there (mssql its not my typical day to day database, my knowledge of it is seriously limitated) that are missing your question.






share|improve this answer























  • Thank you! I'm just looking to write this in PHP/laravel now and I'll confirm if it worked
    – NoStupidQuestions
    Nov 8 at 13:11










  • @NoStupidQuestions maybe give this a try stackoverflow.com/questions/48261495/…
    – Andrea Golin
    Nov 8 at 13:12










  • It's working! My solution was similar to something there: $datastring = file_get_contents($request->file('photo')); $unpack = unpack("H*hex", $datastring); $unpack = '0x'.$unpack['hex']; $answer = DB::raw("CONVERT(VARBINARY(MAX), $unpack)"); Then I use $answer in the insert command down below. Thanks again for your help!
    – NoStupidQuestions
    Nov 8 at 13:41















up vote
0
down vote



accepted







up vote
0
down vote



accepted






You must decode your base64 string to binary prior to insert it onto varbinary field, as it will accept only binary data.



The base64 permits a safe binary file transmission, but it is not a valid binary value for mssql varbinary, as it is a string type.



DECLARE @string varchar(20)

SET @string = 'Hello World'

SELECT CONVERT(varbinary, @string)


Also, if your are actually using mssql, you should add mssql tag to your question accordingly, there a lot of people with a lot of mssql skills out there (mssql its not my typical day to day database, my knowledge of it is seriously limitated) that are missing your question.






share|improve this answer














You must decode your base64 string to binary prior to insert it onto varbinary field, as it will accept only binary data.



The base64 permits a safe binary file transmission, but it is not a valid binary value for mssql varbinary, as it is a string type.



DECLARE @string varchar(20)

SET @string = 'Hello World'

SELECT CONVERT(varbinary, @string)


Also, if your are actually using mssql, you should add mssql tag to your question accordingly, there a lot of people with a lot of mssql skills out there (mssql its not my typical day to day database, my knowledge of it is seriously limitated) that are missing your question.







share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 8 at 13:29

























answered Nov 8 at 13:01









Andrea Golin

650314




650314












  • Thank you! I'm just looking to write this in PHP/laravel now and I'll confirm if it worked
    – NoStupidQuestions
    Nov 8 at 13:11










  • @NoStupidQuestions maybe give this a try stackoverflow.com/questions/48261495/…
    – Andrea Golin
    Nov 8 at 13:12










  • It's working! My solution was similar to something there: $datastring = file_get_contents($request->file('photo')); $unpack = unpack("H*hex", $datastring); $unpack = '0x'.$unpack['hex']; $answer = DB::raw("CONVERT(VARBINARY(MAX), $unpack)"); Then I use $answer in the insert command down below. Thanks again for your help!
    – NoStupidQuestions
    Nov 8 at 13:41




















  • Thank you! I'm just looking to write this in PHP/laravel now and I'll confirm if it worked
    – NoStupidQuestions
    Nov 8 at 13:11










  • @NoStupidQuestions maybe give this a try stackoverflow.com/questions/48261495/…
    – Andrea Golin
    Nov 8 at 13:12










  • It's working! My solution was similar to something there: $datastring = file_get_contents($request->file('photo')); $unpack = unpack("H*hex", $datastring); $unpack = '0x'.$unpack['hex']; $answer = DB::raw("CONVERT(VARBINARY(MAX), $unpack)"); Then I use $answer in the insert command down below. Thanks again for your help!
    – NoStupidQuestions
    Nov 8 at 13:41


















Thank you! I'm just looking to write this in PHP/laravel now and I'll confirm if it worked
– NoStupidQuestions
Nov 8 at 13:11




Thank you! I'm just looking to write this in PHP/laravel now and I'll confirm if it worked
– NoStupidQuestions
Nov 8 at 13:11












@NoStupidQuestions maybe give this a try stackoverflow.com/questions/48261495/…
– Andrea Golin
Nov 8 at 13:12




@NoStupidQuestions maybe give this a try stackoverflow.com/questions/48261495/…
– Andrea Golin
Nov 8 at 13:12












It's working! My solution was similar to something there: $datastring = file_get_contents($request->file('photo')); $unpack = unpack("H*hex", $datastring); $unpack = '0x'.$unpack['hex']; $answer = DB::raw("CONVERT(VARBINARY(MAX), $unpack)"); Then I use $answer in the insert command down below. Thanks again for your help!
– NoStupidQuestions
Nov 8 at 13:41






It's working! My solution was similar to something there: $datastring = file_get_contents($request->file('photo')); $unpack = unpack("H*hex", $datastring); $unpack = '0x'.$unpack['hex']; $answer = DB::raw("CONVERT(VARBINARY(MAX), $unpack)"); Then I use $answer in the insert command down below. Thanks again for your help!
– NoStupidQuestions
Nov 8 at 13:41




















 

draft saved


draft discarded



















































 


draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53206843%2flaravel-base64-image-not-uploading%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Schultheiß

Verwaltungsgliederung Dänemarks

Liste der Kulturdenkmale in Wilsdruff