Undefined offset: 1 in

Hello guys!

I want to upload image using the Croppie.js. My upload.php looks like this:

<?php
	$data = $_POST["image"];
	$image_array_1 = explode(";", $data);
	$image_array_2 = explode(",", $image_array_1[1]);
	$data = base64_decode($image_array_2[1]);
	$imageName = time() . '.png';
	file_put_contents($imageName, $data);

	echo $imageName;
?>

I can upload the cropped image but it keeps saying: Notice : Undefined offset: 1 in C:\xampp\htdocs\test\new\upload.php on line 9

Notice : Undefined offset: 1 in C:\xampp\htdocs\test\new\upload.php on line 10

Any idea?

Which line in the code you posted is line 9 line 10 the line the error refers to?
I guess it’s berween these two:-

var_dump($data) to see what’s actually there.
The chances are there is an array with only one entry, so the second key [1] does not exist.

And the underlying message that arrays are 0 indexed, so [0] is the first entry, not [1].

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.