小编Emi*_*ily的帖子

imagecreatefrompng()使黑色背景而不是透明?

我使用PHP和GD库制作缩略图,但我的代码将png透明度变成纯黑色,是否有改进我的代码的解决方案?

这是我的php缩略图制造商代码:

function cropImage($nw, $nh, $source, $stype, $dest) {
     $size = getimagesize($source);
     $w = $size[0];
      $h = $size[1];

      switch($stype) {
          case 'gif':
          $simg = imagecreatefromgif($source);
          break;
          case 'jpg':
          $simg = imagecreatefromjpeg($source);
          break;
          case 'png':
          $simg = imagecreatefrompng($source);
          break;
      }

      $dimg = imagecreatetruecolor($nw, $nh);
      $wm = $w/$nw;
      $hm = $h/$nh;
      $h_height = $nh/2;
      $w_height = $nw/2;

      if($w> $h) {
          $adjusted_width = $w / $hm;
          $half_width = $adjusted_width / 2;
          $int_width = $half_width - $w_height;
          imagecopyresampled($dimg,$simg,-$int_width,0,0,0,$adjusted_width,$nh,$w,$h);
      } elseif(($w <$h) || ($w == …
Run Code Online (Sandbox Code Playgroud)

php gd thumbnails

40
推荐指数
4
解决办法
7万
查看次数

Curl会自动显示结果吗?

我正在使用php 5.3.2,当我执行curl时,它直接显示结果而不添加print或echo函数.

这是我的代码:

<?php
$pvars = array('query' => 'ice age', 'orderby' => 'popularity');
$timeout = 30;
$myurl = "http://www.website.com";
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $myurl);
curl_setopt($curl, CURLOPT_TIMEOUT, $timeout);
curl_setopt($curl, CURLOPT_POST, 1);
curl_setopt($curl, CURLOPT_POSTFIELDS, $pvars);
$xml = curl_exec($curl);
curl_close ($curl);
?>
Run Code Online (Sandbox Code Playgroud)

我的代码有什么问题以及为什么它会显示结果?

php curl

19
推荐指数
1
解决办法
2万
查看次数

如何防止特定目录运行Php,Html和Javascript语言?

假设我有一个图像上传程序脚本,我想通过仅将其显示为纯文本来阻止上传目录执行Php甚至html,我在许多网站上看到了这个技巧,但我不知道他们是如何做到的.

简而言之,如果我上传evil.php到该目录,并且我尝试访问它,我将只看到纯文本源,没有执行html或php.(但我仍然希望图像正常出现)

我知道我可以这样做,header("content-type:text/plain");但这对我没有帮助,因为我想要的是,content-type:text/plain服务器自动设置从上传目录输出的每一件事,除了图像.

注意:我正在运行php 5.3.2/Cent OS和最新的cPanel.

谢谢

php security upload centos

9
推荐指数
1
解决办法
7678
查看次数

jQuery,Animate opacity为1然后删除opacity属性,使其在IE上更好看

我在所有浏览器中尝试了jQuery fadeIn动画,它运行良好,但在IE上却没有那么多.在附加CSS不透明度之后,Alpha png图像是如此令人毛骨悚然,但我有一个想法,我不知道如何使用jQuery实现它.

想法是淡化元素,当动画完成时,它将自动删除不透明度属性,以使图像质量更好.

怎么做?

注意:我使用的是Animate,而不是FadeIn.

谢谢

javascript jquery

4
推荐指数
2
解决办法
9977
查看次数

如何正确 substr html 实体?

我有这样的:

$mytext="that&#039;s really &quot;confusing&quot; and &lt;absolutly&gt; silly";
echo substr($mytext,0,6);
Run Code Online (Sandbox Code Playgroud)

在这种情况下,输出将是:that&#而不是that's

我想要的是将 html 实体计算为 1 个字符,然后是 substr,因为我总是在文本末尾得到损坏的 html 或一些晦涩的字符。

请不要建议我先 html 解码然后 substr 然后编码它,我想要一个干净的方法:)

谢谢

php html-entities

4
推荐指数
1
解决办法
6470
查看次数

为什么javascript IF只能运行一次?

我有javascript代码,它复制输入文件的值,并在文本框中实时传递.

<script>
function copyit(){

var thephoto=document.getElementById('thephoto').value;
var fileonchange=document.getElementById('fileonchange').value;

if(!thephoto==fileonchange){
document.getElementById('fileonchange').value=thephoto;
}

}

window.setInterval("copyit()", 500);  
</script>

Choose File : <input type="file" id="thephoto"><br>
Here Is the file name : <input type="text" id="fileonchange">
Run Code Online (Sandbox Code Playgroud)

遗憾的是,这只能工作一次,然后在再次更改文件时停止粘贴值.(我的意思是你应该重新加载页面再次工作)

IF有缓存的东西?你可以自己试试看代码.

谢谢你们

javascript javascript-events

1
推荐指数
1
解决办法
364
查看次数

如何绑定数组?

说我有这3个阵列:

Product(milk,candy,chocolate)
Colors(white,red,black)
Rating(8,7,9)
Run Code Online (Sandbox Code Playgroud)

如何创建一个循环来绑定这些数组,这样我在每个循环中得到3个变量: $product $color $rating

所以通过示例我将输出如下:

牛奶白色并且具有等级的8 /10

糖果红色,并且具有等级的7 /10

巧克力黑色的,有等级的9 /10

谢谢

php arrays

1
推荐指数
1
解决办法
143
查看次数