Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/arduino/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Salesforce/php-下载的图像附件已损坏-有什么想法吗?_Php_Web Services_Salesforce - Fatal编程技术网

Salesforce/php-下载的图像附件已损坏-有什么想法吗?

Salesforce/php-下载的图像附件已损坏-有什么想法吗?,php,web-services,salesforce,Php,Web Services,Salesforce,以下是我使用php工具包和企业wsdl从Salesforce.com下载附件的代码: header('Content-Type: application/force-download'); header('Content-Disposition: inline; filename="image.jpg"'); $mySforceConnection = getConnection(); $query = "SELECT Id, Name, Body

以下是我使用php工具包和企业wsdl从Salesforce.com下载附件的代码:

    header('Content-Type: application/force-download');
    header('Content-Disposition: inline; filename="image.jpg"');        
    $mySforceConnection = getConnection();
    $query = "SELECT Id, Name, Body from Attachment Where Id ='" .$id ."'";
    $queryResult = $mySforceConnection->query($query);

    $records = $queryResult->records;
    print_r(base64_decode($records[0]->fields->Body));
当我这样做时,文件会以正确的字节数正确下载,但当我打开图像时,windows图像查看器会说它已损坏。知道为什么会这样吗


同样的代码也适用于PDF和文本文件。

正如@eyescream所提到的,您确实希望只回显输出。使用
print\r
功能时,会在输出中添加额外的制表符和换行符,以使其更具可读性。普通的
回声
可以正常输出

header('Content-Type: application/force-download');
header('Content-Disposition: inline; filename="image.jpg"');

$mySforceConnection = getConnection();

$query = "SELECT Id, Name, Body from Attachment Where Id ='" .$id ."'";
$queryResult = $mySforceConnection->query($query);

$records = $queryResult->records;
echo base64_decode($records[0]->fields->Body);

正如@eyescream所提到的,您确实希望只回显输出。使用
print\r
功能时,会在输出中添加额外的制表符和换行符,以使其更具可读性。普通的
回声
可以正常输出

header('Content-Type: application/force-download');
header('Content-Disposition: inline; filename="image.jpg"');

$mySforceConnection = getConnection();

$query = "SELECT Id, Name, Body from Attachment Where Id ='" .$id ."'";
$queryResult = $mySforceConnection->query($query);

$records = $queryResult->records;
echo base64_decode($records[0]->fields->Body);

除了windows图像查看器,您是否尝试过其他功能?可能扩展名与文件类型不匹配?你确定是jpg吗?不会把打印弄糟吗?我的意思是,
echo
很简单,
print\u r
会做缩进等,如果用
标签包装代码,会让代码看起来很漂亮……除了windows图像查看器,你试过其他东西吗?可能扩展名与文件类型不匹配?你确定是jpg吗?不会把打印弄糟吗?我的意思是,
echo
很简单,
print\u r
会做缩进等,如果用
标签包装代码,会让代码看起来很漂亮。。。