任何人都可以告诉我如何为以下代码定义索引:
<?php
///////////////////////////////////////////////////////////////////////////////
// GENERAL SETTINGS
///////////////////////////////////////////////////////////////////////////////
$folder_sort_order = "asc"; //asc or desc
$image_sort_order = "asc"; //asc or desc
$mainfolder = "autogallery"; //only change this if you rename the folder
# path to the script, shouldnt need to change it unless you change the path
# for example $path_to_script = "/path/to/my/script/autogallery/" . $mainfolder;
$path_to_script = "/autogallery/" . $mainfolder;
///////////////////////////////////////////////////////////////////////////////
// CODE STARTS HERE, YOU SHOULD NOT HAVE TO EDIT BELOW THIS LINE
///////////////////////////////////////////////////////////////////////////////
$basepath = $_SERVER["DOCUMENT_ROOT"] . $path_to_script;
$gallerypath = $basepath . "/galleries/";
$galleryid = $_REQUEST['directory']; //get gallery id from ajax request
//instantiate the autoGallery class
require 'autoGallery.php';
$autogallery = new autoGallery();
//if ajax is disabled, degrade
if(empty($galleryid)) {
$galleryid = $_GET['gid'];
}
//get all photos from selected gallery or from latest gallery
if(isset($galleryid)){
$galleryname = $autogallery->getGalleryNameByID($gallerypath, $galleryid);
} else {
$galleryname = $autogallery->latestGallery($gallerypath, $folder_sort_order);
}
$imagepath = $gallerypath . $galleryname . "/";
$imagefiles = $autogallery->getPhotos($imagepath, $image_sort_order);
//remove id from gallery name for viewing purposes
$galleryname = substr($galleryname, 4);
//get gallery list to build nav
$gallerylist = $autogallery->getGalleries($gallerypath, $folder_sort_order);
//remove base path from image path
$imagepath = str_replace($basepath . "/", "", $imagepath);
//path for ajax request
$datapath = str_replace($basepath . "/", "", $path_to_script);
我不断收到以下错误消息:注意:未定义的索引:C中的目录:第19行的wampwwwautogalleryautogallerysettings.php注意:未定义的索引:C中的gid:第27行的wampwwwautogalleryautogallerysettings.php第19行的代码是:
$galleryid = $_REQUEST['directory']; //get gallery id from ajax request
第27行的代码是:
$galleryid = $_GET['gid'];
第26-28行的完整代码:
if(empty($galleryid)) {
$galleryid = $_GET['gid'];
}
答案 0 :(得分:2)
在使用
之前检查变量是否存在功能
if(empty($galleryid)) {
if (isset($_GET['gid'])) {
$galleryid = $_GET['gid'];
}
}
$_GET['gid']
和$_REQUEST['directory']
都没有设置