Search code examples
phpxampp

get php file execution result


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);
}
?>

Solution

  • 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);