I'm trying to use random numbers to store the image names of uploaded images which works perfectly. Now, I have to use the number in another function, but it changes when used in another function.
$GLOBALS['rand'] = rand() . '.png';
if(isset($_POST["image"])){
$data = $_POST["image"];
$image_array_1 = explode(";", $data);
$image_array_2 = explode(",", $image_array_1[1]);
$data = base64_decode($image_array_2[1]);
file_put_contents( $GLOBALS['rand'], $data);
echo '<img src="includes/'.$GLOBALS['rand'].'" class="img-thumbnail" />';
}
This is to display the cropped image and give it a name, before upload. Now to upload:
if(isset($_POST["submit"])){
$pic = $GLOBALS['rand'];
$sql = "INSERT INTO users (pic) VALUES ('$pic');
}
I expect that when using the $GLOBALS['rand'] in the second function, the generated number is the same.
Aucun commentaire:
Enregistrer un commentaire