PHP代码在本地工作但不在服务器上工作(cPanel)

时间:2016-06-25 14:04:23

标签: php

我的网站上有以下PHP代码来生成图像相册,而不必手动创建它们:

<?php
$folder_path = 'assets/albums/album1/thumbnails/';
$num_files = glob($folder_path . "*.{jpg,gif,png,bmp}", GLOB_BRACE);
$folder = opendir($folder_path);

$folder_path_o = 'assets/albums/album1/';
$num_files_o = glob($folder_path_o . "*.{jpg,gif,png,bmp}", GLOB_BRACE);
$folder_o = opendir($folder_path_o);

if($num_files > 0)
{
    while (false !== ($file = readdir($folder)) && ($file_o = readdir($folder_o))) {
        $file_path = $folder_path.$file;
        $extension = strtolower(pathinfo($file , PATHINFO_EXTENSION));

        $file_path_o = $folder_path_o.$file_o;
        $extension_o = strtolower(pathinfo($file_o , PATHINFO_EXTENSION));

        if (($extension == 'jpg' || $extension == 'png' || $extension == 'gif' || $extension == 'bmp') && ($extension_o == 'jpg' || $extension == 'png' || $extension == 'gif' || $extension == 'bmp')) {
            ?>
            <li><a href="<?php echo $file_path_o; ?>" data-lightbox="<?php echo $folder; ?>"><img src="<?php echo $file_path; ?>" alt="<?php echo $album_name; ?>"></a></li>
            <?php
        }
    }
}
else {
    echo "the folder was empty";
}
closedir($folder);
?>

此代码在我的localhost上完美运行。但是,当我将其上传到服务器(使用cPanel在name.com上共享主机)时,它似乎只是部分工作:

  • 在localhost上,它会生成整个相册,显示指定文件夹的所有图像($folder_pathfolder_path_o)。
  • 在服务器上,它只返回一个图像,而不是整个文件夹(这使我相信这不是一个与权限相关的问题)

有什么想法吗?非常感谢任何帮助。

1 个答案:

答案 0 :(得分:0)

您可以检查它,它与服务器本身有关,您无法确定。

switch ($_FILES['upfile']['error']) {
        case UPLOAD_ERR_OK:
            echo "Uploading success";
        case UPLOAD_ERR_INI_SIZE:
        echo "The uploaded file exceeds the upload_max_filesize directive in php.ini.";
    case UPLOAD_ERR_FORM_SIZE:
        echo "The uploaded file exceeds the MAX_FILE_SIZE directive that was specified in the HTML form.";
    case UPLOAD_ERR_NO_TMP_DIR:
        echo "Missing a temporary folder.";
    case UPLOAD_ERR_INI_SIZE:
        echo "The uploaded file exceeds the upload_max_filesize directive in php.ini.";
    case UPLOAD_ERR_CANT_WRITE:
        echo "Failed to write file to disk";


        default:
            throw new RuntimeException('Unknown errors.');
    }