Asked  8 Months ago    Answers:  5   Viewed   28 times

If it's Path_To_DocumentRoot/a/b/c.php,should always be /a/b.

I use this:


But it won't work when it's included by another file in a different directory.


I need a relative path to document root .It's used in web application.

I find there is another question with the same problem,but no accepted answer yet.

PHP - Convert File system path to URL



Do you have access to $_SERVER['SCRIPT_NAME']? If you do, doing:


Should work. Otherwise do this:

In PHP < 5.3:

substr(dirname(__FILE__), strlen($_SERVER['DOCUMENT_ROOT']));

Or PHP >= 5.3:

substr(__DIR__, strlen($_SERVER['DOCUMENT_ROOT']));

You might need to realpath() and str_replace() all to / to make it fully portable, like this:

substr(str_replace('\', '/', realpath(dirname(__FILE__))), strlen(str_replace('\', '/', realpath($_SERVER['DOCUMENT_ROOT']))));
Wednesday, March 31, 2021
answered 8 Months ago

Try to use RecursiveIteratorIterator in combination with RecursiveDirectoryIterator

$path = realpath('/path/you/want/to/search/in');

$objects = new RecursiveIteratorIterator(
               new RecursiveDirectoryIterator($path), 

foreach($objects as $name => $object){
    if($object->getFilename() === 'work.txt') {
        echo $object->getPathname();

Additional reading:

Wednesday, March 31, 2021
answered 8 Months ago

This is going to get the first 10 pages of data. I limited it to 10 to prevent it from eating my quota. If you remove that it will continue to chug away getting all the rows and eating up your quota.

NOTE: This is only going to work if you have a single report. If you have more then one report then you are going to have to do some fancy stuff to apply the correct pageToken to each report and remove the reports which are complete. At this time there is no report Id or way of matching up what you sent to the report that is returned other than its place in the reports array.

$service = new Google_Service_AnalyticsReporting($client); 

// Create the DateRange object.
$dateRange = new Google_Service_AnalyticsReporting_DateRange();

// Create the Metrics object.
$sessions = new Google_Service_AnalyticsReporting_Metric();

//Create the Dimensions object.
$date = new Google_Service_AnalyticsReporting_Dimension();
$pagePath = new Google_Service_AnalyticsReporting_Dimension();

// Create the ReportRequest object.
$request = new Google_Service_AnalyticsReporting_ReportRequest();

$body = new Google_Service_AnalyticsReporting_GetReportsRequest();
$body->setReportRequests( array( $request) );
$data =  $service->reports->batchGet( $body );

// Remove count if you really want everything.
$cnt = 0; 
while ($data->reports[0]->nextPageToken > 0 && $cnt < 10) {
    // There are more rows for this report.
    $data =  $service->reports->batchGet( $body );

I put a tutorial up on it Google Analytics V4 pagination and the full code i used can be found on GitHub note this code was ripped from my sample project.

Wednesday, March 31, 2021
answered 8 Months ago

Assuming that you use the DATETIME-format as datatype in your database this should help you:

$start =  date("h:i:s", strtotime($this->input->post('start')));
$end =  date("h:i:s", strtotime($this->input->post('end')));
$sql = "SELECT materialID FROM schedule WHERE date_reserve = ? AND TIME(start_time) >= ? AND TIME(end_time) <= ?";

Edit: So if you use TIME-format you only have to change the format of the values you are inserting:

$start =  date("h:i:s", strtotime($this->input->post('start')));
$end =  date("h:i:s", strtotime($this->input->post('end')));
Saturday, May 29, 2021
answered 5 Months ago

When a webpage is requested from a server. The server looks at the path (i.e. to figure out which file to serve and from where.

As I understand it, what you want to do is have your index.php handle all the requests. The way you would do this to use URL Rewriting.

Assuming you are using an apache web server, you can use something called *mod_rewrite* to do this. See more on mod_rewrite here.

For the specific rules to use, you probably want to use something like the code in V_K's answer.

Saturday, May 29, 2021
answered 5 Months ago
Only authorized users can answer the question. Please sign in first, or register a free account.
Not the answer you're looking for? Browse other questions tagged :