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);
}
?>
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);
Related
Similar question has been asked previously but it didn't solve my problem so i am asking here again. Actually i am uploading base64 image file to php server and i have to save it there. I tried every suggested help but nothing works for me. my code
// here is my base64 code for image
data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgFBgcGBQgHBgcJCAgJDBMMDAsLDBgREg4THBgdHRsYGxofIywlHyEqIRobJjQnKi4vMTIxHiU2OjYwOiwwMTD/2wBDAQgJCQwKDBcMDBcwIBsgMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDAwMDD/wAARCAC1ALUDASIAAhEBAxEB/8QAHwAAAQUBAQEBAQEAAAAAAAAAAAECAwQFBgcICQoL/8QAtRAAAgEDAwIEAwUFBAQAAAF9AQIDAAQRBRIhMUEGE1FhByJxFDKBkaEII0KxwRVS0fAkM2JyggkKFhcYGRolJicoKSo0NTY3ODk6Q0RFRkdISU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x0asIU1Fo8rWVqmGf71FFeoeWNYVTuYRMnzmiihCZWi1HUdLlC2OoXNvj/nlKy/yNdHZfE7xNDbNBeXUd/Ax2FZ4xux7MMH880UV0JJxucrbUrI9Y+GXjT/AIS2F4X08WrWyqhYTFt2B1xgY/Ou3C4h8xcD2IoorFrU06Gv4c+5P/vD+tbHIOQcZ5IoorSOxm9xQoYE+nauP8f+NE8G2Ul0NMW8Zc8ed5ecf8BNFFBKPI7/APaJ12Z8aXo2nWif9Ni8x/QqP0rCv/i7431Byv8Aa62qn+G2gRP1wT+tFFTM1gkZ0viDX75tt7rl/Kf+upH6CnQqZP8AXSyy/wC+5NFFYSOqCRa/1f3adiiis0bMh3fX86kFw69DRRVszuPzR/yzoooARQcfeNFFFID/2Q==
$src="data:image/jpeg;base64,/9j/4AAQSkZJRgABAQAAAQABAAD//gA7Q1JFQVRPUjogZ2QtanBlZyB2MS4wICh1c2luZyBJSkcgSlBFRyB2OTApLCBxdW... ";
// above the example of image base64 file
// and server side code in php, i have posted base64 to php
$img_part = explode(";base64,",$_POST['base64']);
$img_type_aux = explode("image/",$img_part[0]);
$ext = $img_type_aux[1];
$image_base64 = base64_decode($img_part[1]);
// i have tried all possible code like here $name = random_value+$ext
file_put_contents($name,$image_base64); // didn't work then i used str_replace
$image_base64 = str_replace(' ','+',$image_base64);
file_put_contents($name,$image_base64); // i also didn't work
$fp = fopen($name,"wb");
fwrite($fp,$image_base64); // i also didn;t work
fclose($fp);
please someone help me,
Use this function This will work.
function convertBase64toimage($image_string){
$name='test_with_new_image.jpeg';
$folderPath=$_SERVER['DOCUMENT_ROOT'] . "/test/";
$img_part = explode(";base64,",$image_string);
$img_type_aux = explode("image/",$img_part[0]);
$ext = $img_type_aux[1];
$image_base64 = base64_decode($img_part[1]);
$file = $folderPath .$name;
file_put_contents($file,$image_base64);
}
$string='data:image/jpeg;base64,/9j/4AAQSkZJRgABAQEAYABgAAD/2wBDAAgFBgcGBQgHBgcJCAgJDBMMDAsLDBgREg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FUqUl1t6GEsVRbvyNv8AvNv8rHA3U3i6/wD+WVtbpu/h5NM1Pw5e399aXD/8sfvfL1Ndq3iTQ0/5iVt/wFwaafFegJ/zEoP++qieGp1E4zkEMZUhJSpxS+Rl6FY3Fhfeb5TOm3b92ukluP8ARJXdGTap+9WYfGGgf8/8VUtU8YaK9jOkN0ruylaqjSp0IckHojnq1KlefPNanlE0+/Vrt03fNIa7f4Qult/aG9tm6SuEEtuk8j71+8dtbfgvU7Kw897m4VNzfxVlBNSufR47Exq4VUlbp+Be+Jc0M+vgq/3UAorn/Ft7FeamZLeTcmKK5alKUpuSZx0asIU1Fo8rWVqmGf71FFeoeWNYVTuYRMnzmiihCZWi1HUdLlC2OoXNvj/nlKy/yNdHZfE7xNDbNBeXUd/Ax2FZ4xux7MMH880UV0JJxucrbUrI9Y+GXjT/AIS2F4X08WrWyqhYTFt2B1xgY/Ou3C4h8xcD2IoorFrU06Gv4c+5P/vD+tbHIOQcZ5IoorSOxm9xQoYE+nauP8f+NE8G2Ul0NMW8Zc8ed5ecf8BNFFBKPI7/APaJ12Z8aXo2nWif9Ni8x/QqP0rCv/i7431Byv8Aa62qn+G2gRP1wT+tFFTM1gkZ0viDX75tt7rl/Kf+upH6CnQqZP8AXSyy/wC+5NFFYSOqCRa/1f3adiiis0bMh3fX86kFw69DRRVszuPzR/yzoooARQcfeNFFFID/2Q==';
$a=convertBase64toimage($string);
And output of the code
i have a file with extension PDF and DOCX, and when i download it from my server, the file cannot opened and the size become 1kb, when in my server folder it has 199kb size. iam using database to store the file path and filename, here is my view to download the file
View
<?php echo $details->FILE_NAME; ?>
and my controller
Admin_Controls.php
function download_proposal($id_pemesanan) {
$this->load->helper('download');
$this->load->model('gedung/gedung_model');
$temp_id = substr($id_pemesanan, 7); //i cut the string because it content prefix string
$data = $this->gedung_model->get_proposal_by_id($temp_id);
$path = file_get_contents($data->PATH.$data->FILE_NAME);
$file_name = $data->FILE_NAME;
force_download($file_name, $data);
}
my model
Gedung_Model.php
public function get_proposal_by_id($id_pemesanan) {
$sql = "SELECT * FROM pemesanan_details WHERE ID_PEMESANAN = $id_pemesanan";
$query = $this->db->query($sql);
$hasil = $query->row();
return $hasil;
}
my problem is just after i download the file, it becomes corrupted and cannot open, like i say the size become 1kb. all works well from user click to download until the download process
Thanks in advice
I would like to check the path . You can use absolute path of the file for testing purpose instead of dynamic generated path .
Can someone explain me why when i POST RAW Data for example "test.txt" in the below script
<?php
echo file_get_contents("php://input");
?>
it only prints the text "test.txt" instead of the file contents of that file?
Thank you
Your code reads the contents of the raw POST data and echoes it back.
Whereas what you want is this:
// retrieve the requested filename
$fileName = file_get_contents("php://input");
// echo the contents of the requested file
echo file_get_contents($fileName);
Depending on what you're trying to, you may wish to sanitize the $fileName input (not shown: too broad) and restrict access to a specific local directory:
$path = $myLocalDirectory . DIRECTORY_SEPARATOR . $fileName;
if (file_exists($path) {
echo file_get_conents($path);
}
Try like this ..
$input = "abc.txt";
echo file_get_contents($input);
It gives the content of the text file abc.txt
my question is how to get the content of a file from a input file
becausethe only thing im getting is the name of the file not the
full path of the file.
$handle = file_get_contents($this->data['btnBrowse']);
$absolute = basename($this->data['btnBrowse']);
var_dump($handle);
var_dump($absolute);
This should work:
$file = new File($dir);
$contents = $file->read();
$file->close();
I have a data URI I am getting from javascript and trying to save via php. I use the following code which gives a apparently corrupt image file:
$data = $_POST['logoImage'];
$uri = substr($data,strpos($data,",")+1);
file_put_contents($_POST['logoFilename'], base64_decode($uri));
data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAoAAAAKCAYAAACNMs 9AAAACXBIWXMAAAsTAAALEwEAmpwYAAAAxklEQVQYlYWQMW7CUBBE33yITYUUmwbOkBtEcgUlTa7COXIVV5RUkXKC5AxU EdyZVD4kyKxkwIrr9vd0c7Oih aopinLNsF6Qkg2XW4XJ7LGFsAAcTV6lF5/jLdbALA9XDAXYfthFQVx OrmqKYK88/7rbbMFksALieTnzu9wDYTj6f70PKsp2kwAiSvjXNcvkWpAfNZkzWa/5a9yT7fdoX7rrB7hYh2fXo9HdjPYQZu3MIU8bYIlW20y0RUlXG2Kpv/vfwLxhTaSQwWqwhAAAAAElFTkSuQmCC
Below the code is the actual image as a Data-URI. 'logoImage' is the string above, and $uri is the string minus 'image/jpeg;base64,'.
A quick look at the PHP manual yields the following:
If you want to save data that is derived from a Javascript
canvas.toDataURL() function, you have to convert blanks into plusses.
If you do not do that, the decoded data is corrupted:
$encodedData = str_replace(' ','+',$encodedData);
$decodedData = base64_decode($encodedData);
The data URI you have in your example is not a valid PNG image. This will never work and is unrelated to the code, it's related to the data.
Does not apply but might be of interest:
file_put_contents($_POST['logoFilename'], file_get_contents($data));
The idea behind: PHP itself can read the contents of data URIs (data://) so you don't need to decode it on your own.
Note that the official data URI scheme (ref: The "data" URL scheme RFC 2397) does not include a double slash ("//") after the colon (":"). PHP supports with or without the two slashes.
# RFC 2397 conform
$binary = file_get_contents($uri);
# with two slashes
$uriPhp = 'data://' . substr($uri, 5);
$binary = file_get_contents($uriPhp);
The all code that works :
$imgData = str_replace(' ','+',$_POST['image']);
$imgData = substr($imgData,strpos($imgData,",")+1);
$imgData = base64_decode($imgData);
// Path where the image is going to be saved
$filePath = $_SERVER['DOCUMENT_ROOT']. '/ima/temp2.png';
// Write $imgData into the image file
$file = fopen($filePath, 'w');
fwrite($file, $imgData);
fclose($file);
I have another way to do this with PHP.
$img = str_replace(' ','+',$img);
$i = explode(',', $img);
$imgData = array_pop($i);
$newName = 'digital_file/'. rand(10, 16) . '.' . str_replace('/', '.', mime_content_type($img) );
// data:image/png;base64
$imgData = base64_decode($imgData);
Now you can use file_put_contents($newName) to create the image file.
Produces a file with a random numerical name (e.g. "123123.image.png"). And of course it has correct mime type.