简体   繁体   中英

Extra text comes from shell_exec command when executed from php

I am using s3cmd to get files from AWS to my ubuntu server.

s3cmd get s3://bucket/filename newfilename

It works fine when run from terminal of ubuntu.

But when I run from php like below

$query1 = 's3cmd get s3://bucket/filename newfilename';
$q1 = serialize(shell_exec($query1));
$data2 = array( 'data' => $q1);
header('Content-type: application/json');
echo json_encode( $data2 );

It works but response from json_encode it concatenated with extra text.

{"data":"s:122:\"File s3:............

What is s:122 and how to remove this. I am not looking for sub_string though.

When you serialize some value - in a result string there's type of value and value itself. s:122 , you asked about, says that values is a s tring with length 122 . So if you don't want this string appear - don't serialize value.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM