English 中文(简体)
PHP pathinfo作为不从事服务器工作的形象属性
原标题:PHP pathinfo as image attribute not working on server

使用以下代码扫描图像的夹:

<?php
    $dir =  img/product/subproduct/cat/ ;
    $scan = scandir($dir);
        for ($i = 0; $i<count($scan); $i++) {
            $path_parts = pathinfo($scan[$i]); // to remove file extension
            if ($scan[$i] !=  .  && $scan[$i] !=  .. ) {
                echo  <img src="  . $dir . $scan[$i] .  " alt="  . $path_parts[ filename ] .  " width="50" height="50" /> ;
            }
        };
?>

接着,我展示了被点击的形象的更大版本,并增加了一个字塔,作为上限:

$( #id img ).click(function () {
    var imageName = $(this).attr( alt );
    var chopped = imageName.split( . );
    $( #titlel ).empty();
    $( #titlel )
        .prepend(chopped[0]);
    $img = $(this);
    $( #idBig img ).attr( src , $img.attr( src ));
});

这既涉及当地服务器,也涉及我本人的服务器,但一旦我将其转移到我的客户服务器上,在我点击图像时,封顶就没有出现。

值得注意的是,我不得不在我的客户服务器上添加“AddHandler application/x-httpd-php5 .php”的“htaccess file”,以便scandir发挥作用。 这是否相关? 我如何确定这一点?

我赞赏任何建议。

最佳回答

正如菲尼亚格提到的那样,它看起来像PHP >可以查阅档案名称的路径信息;=5.2.0,这样,如果你使用较早版本,你可以尝试(没有测试):

$path_parts = pathinfo($scan[$i]);

// Subtract strlen of extension from strlen of entire filename
//  (+1 for  . )
$filenameStrLen = (strlen($path_parts[ basename ]) - strlen($path_parts[ extension ])) + 1;

// Substr basename from 0 to strlen
$filenameWithNoExtension = substr($path_parts[ basename ], 0, $filenameStrLen);    

页: 1 它是为这种功能而建造的。

问题回答

manual ,filename。 返回阵列的关键(或PATHINFO_FILENAME)要求php5.2或更新的。 为了查明这一问题是否如此,通过审查已提交的超文本文件的来源代码来检查结果。

另外,你也不必修改一份供作工的单程文件。 相反,修改全球服务器配置。





相关问题
Brute-force/DoS prevention in PHP [closed]

I am trying to write a script to prevent brute-force login attempts in a website I m building. The logic goes something like this: User sends login information. Check if username and password is ...

please can anyone check this while loop and if condition

<?php $con=mysql_connect("localhost","mts","mts"); if(!con) { die( unable to connect . mysql_error()); } mysql_select_db("mts",$con); /* date_default_timezone_set ("Asia/Calcutta"); $date = ...

定值美元

如何确认来自正确来源的数字。

Generating a drop down list of timezones with PHP

Most sites need some way to show the dates on the site in the users preferred timezone. Below are two lists that I found and then one method using the built in PHP DateTime class in PHP 5. I need ...

Text as watermarking in PHP

I want to create text as a watermark for an image. the water mark should have the following properties front: Impact color: white opacity: 31% Font style: regular, bold Bevel and Emboss size: 30 ...

How does php cast boolean variables?

How does php cast boolean variables? I was trying to save a boolean value to an array: $result["Users"]["is_login"] = true; but when I use debug the is_login value is blank. and when I do ...

热门标签