0

i'm new in php. and using php on xampp and also in real server. i have a php file that receives on image as String and saves it as image that im gonna use this file with a library in android that uploads image to php file. the string is sent to php file but no file is saved as image. my problem is that i cant figure out how to get result of executing this php file. i cant get response with my upload library , if i could get echo from this file for test purpose, so i could test it or if i could get error log of execution of file in xampp. but i have no clue how to test php file that is not containing view so i cant echo any thing. this is my php file code:

<?php
if($_POST){
    $data = $_POST['imgBase64'];
    $data = str_replace('data:image/png;base64,', '', $data);
    $data = str_replace(' ', '+', $data);
    $data = base64_decode($data);
    $file = ''.rand() . '.png';
    $success = file_put_contents($file, $data);
    $data = base64_decode($data); 
    $source_img = imagecreatefromstring($data);
    $rotated_img = imagerotate($source_img, 90, 0); 
    $file = 'localhost/serverp/server.parhamcode.ir/'. rand(). '.png';
    $imageSave = imagejpeg($rotated_img, $file, 10);
    imagedestroy($source_img);
}
?>
4
  • 1
    Are you planning to save this image as a BLOB in a database or save it as a .png in a file folder on your server? Commented Feb 23, 2021 at 16:31
  • 1
    How is the file being sent to the server, one would normally expect a file to be in $_FILES. So it would be great if you can show us how the browser is sending the file Commented Feb 23, 2021 at 16:41
  • @CJBroersma i want to save image as jpg file in my server. im testing first on xampp then want to put file in real server. please let me know if file needs change to work. Commented Feb 23, 2021 at 18:32
  • @RiggsFolly the file is sending from a android app by http request. a library that im using in app is turning image to base64 string and sending it to server Commented Feb 23, 2021 at 18:34

1 Answer 1

1

try this:

<?php
file_put_contents('./debug.log', $_POST, FILE_APPEND);

then you'll get a debug.log file under the same folder as your PHP script. you can change $_POST to any variable you want to check.

If you want to echo something in this log file :

file_put_contents('./debug.log', "any string is ok.", FILE_APPEND);
Sign up to request clarification or add additional context in comments.

1 Comment

thank you for answer i will test this and inform you result. is there a way to save echoes that im putting in php in this log file.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.