我的网站上有以下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上共享主机)时,它似乎只是部分工作:
$folder_path
和folder_path_o
)。有什么想法吗?非常感谢任何帮助。
答案 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.');
}