这串代码,在 linux 环境下无法显示图片
<code>$img_url = $_GET['img']; $content = file_get_contents($img_url); header('Content-Type: image/jpeg; charset=UTF-8'); echo $content; </code>
linux 环境的访问地址 demo (存在问题)
mac 环境的访问地址 demo (正常)
win 关机了就不贴了 (正常)
我在这串代码之前添加过 error_reporting(E_ALL);ini_set("display_errors","On");die;
未发现错误,
检查了 linux 环境下的 allow-url-fopen
为 on
,并且可以 print_r
出来,内容相同如下:
<code>����JFIF��;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90 ��C ��C ��j�"�� ���}!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������� ���w!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������?�����2���}x����bi��f(�IQ߆���]/�?</code>
这串字符没太多意义,截取了头部一段贴了上来。
同时添加一个 phpinfo 供大家查看
回复内容:
这串代码,在 linux 环境下无法显示图片
<code>$img_url = $_GET['img']; $content = file_get_contents($img_url); header('Content-Type: image/jpeg; charset=UTF-8'); echo $content; </code>
linux 环境的访问地址 demo (存在问题)
mac 环境的访问地址 demo (正常)
win 关机了就不贴了 (正常)
我在这串代码之前添加过 error_reporting(E_ALL);ini_set("display_errors","On");die;
未发现错误,
检查了 linux 环境下的 allow-url-fopen
为 on
,并且可以 print_r
出来,内容相同如下:
<code>����JFIF��;CREATOR: gd-jpeg v1.0 (using IJG JPEG v62), quality = 90 ��C ��C ��j�"�� ���}!1AQa"q2���#B��R��$3br� %&'()*456789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������� ���w!1AQaq"2�B���� #3R�br� $4�%�&'()*56789:CDEFGHIJSTUVWXYZcdefghijstuvwxyz��������������������������������������������������������������������������?�����2���}x����bi��f(�IQ߆���]/�?</code>
这串字符没太多意义,截取了头部一段贴了上来。
同时添加一个 phpinfo 供大家查看
这个问题于昨夜三点解决,在代码输出之前添加 ob_clean
即可,在 Thinkphp 的调试模式下会有意外输出,但是这个输出是什么尚未找到,而且这个意外输出只有 linux 下才会有,怀疑是框架问题和系统配置之间有什么问题。
正常来说, 应该可以输出图片的。 windows 下,我测试时没有问题。 thinkphp 可能某些应用到ob 缓存了,清理下吧,不然直接在浏览器输出 二进制流可能有问题。
少扩展
freetype,jpegsrc,libpng装上试试
header('Content-Type: image/jpeg; charset=UTF-8');
这行去掉charset=UTF-8
header('Content-Type: image/jpeg');
看了一下,lz的相应头里是 Content-Type: image/jpg
,应该是 Content-Type: image/jpeg
。

TooptimizePHPcodeforreducedmemoryusageandexecutiontime,followthesesteps:1)Usereferencesinsteadofcopyinglargedatastructurestoreducememoryconsumption.2)LeveragePHP'sbuilt-infunctionslikearray_mapforfasterexecution.3)Implementcachingmechanisms,suchasAPC

PHPisusedforsendingemailsduetoitsintegrationwithservermailservicesandexternalSMTPproviders,automatingnotificationsandmarketingcampaigns.1)SetupyourPHPenvironmentwithawebserverandPHP,ensuringthemailfunctionisenabled.2)UseabasicscriptwithPHP'smailfunct

The best way to send emails is to use the PHPMailer library. 1) Using the mail() function is simple but unreliable, which may cause emails to enter spam or cannot be delivered. 2) PHPMailer provides better control and reliability, and supports HTML mail, attachments and SMTP authentication. 3) Make sure SMTP settings are configured correctly and encryption (such as STARTTLS or SSL/TLS) is used to enhance security. 4) For large amounts of emails, consider using a mail queue system to optimize performance.

CustomheadersandadvancedfeaturesinPHPemailenhancefunctionalityandreliability.1)Customheadersaddmetadatafortrackingandcategorization.2)HTMLemailsallowformattingandinteractivity.3)AttachmentscanbesentusinglibrarieslikePHPMailer.4)SMTPauthenticationimpr

Sending mail using PHP and SMTP can be achieved through the PHPMailer library. 1) Install and configure PHPMailer, 2) Set SMTP server details, 3) Define the email content, 4) Send emails and handle errors. Use this method to ensure the reliability and security of emails.

ThebestapproachforsendingemailsinPHPisusingthePHPMailerlibraryduetoitsreliability,featurerichness,andeaseofuse.PHPMailersupportsSMTP,providesdetailederrorhandling,allowssendingHTMLandplaintextemails,supportsattachments,andenhancessecurity.Foroptimalu

The reason for using Dependency Injection (DI) is that it promotes loose coupling, testability, and maintainability of the code. 1) Use constructor to inject dependencies, 2) Avoid using service locators, 3) Use dependency injection containers to manage dependencies, 4) Improve testability through injecting dependencies, 5) Avoid over-injection dependencies, 6) Consider the impact of DI on performance.

PHPperformancetuningiscrucialbecauseitenhancesspeedandefficiency,whicharevitalforwebapplications.1)CachingwithAPCureducesdatabaseloadandimprovesresponsetimes.2)Optimizingdatabasequeriesbyselectingnecessarycolumnsandusingindexingspeedsupdataretrieval.


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

SecLists
SecLists is the ultimate security tester's companion. It is a collection of various types of lists that are frequently used during security assessments, all in one place. SecLists helps make security testing more efficient and productive by conveniently providing all the lists a security tester might need. List types include usernames, passwords, URLs, fuzzing payloads, sensitive data patterns, web shells, and more. The tester can simply pull this repository onto a new test machine and he will have access to every type of list he needs.

Atom editor mac version download
The most popular open source editor
