Jump to content

Getting a page only file url


Manaus
 Share

Recommended Posts

Hi, I'm using this code to get the only file of a page. I uploaded the file using the admin pages.

<? if ($page->name == "myproject3"): 
	$myfile = "somefile.pdf";
	$myfile = $page->documents->get('name='.$myfile);
	echo $myfile->url;

But I get nothing, not even null...

Thanks for any suggestion

Link to comment
Share on other sites

I did not get into all this, but maybe:

$myfile = $page->documents->get("name={$myfile}");

But why not limit "Maximum files allowed" and output it like this:

<?php if($page->documents) {	
	echo $page->documents->url;
} ?>

If you plan to have multiple files uploads, you should leave "Maximum files allowed" option as it is and do foreach.

Edited by Ivan Gretsky
  • Like 2
Link to comment
Share on other sites


<?php

if ($page->name == "myproject3") {

$myfile = "somefile.pdf";

// directly creating the path because you know where it lays and wht it's name is

$myfileUrl = $config->urls->assets.$page->id.'/'.$myfile);

echo $myfileUrl;

}

/* second option: using foreach */

if ($page->name == "myproject3") {

$myfile = "somefile.pdf";

foreach($page->documents as $document) {

if(basename($document->url) != $myfile) continue;

$myfileUrl = $document->url;

}

echo $myfileUrl;

}

  • Like 3
Link to comment
Share on other sites

Hi, I'm using this code to get the only file of a page. I uploaded the file using the admin pages.

<? if ($page->name == "myproject3"): 
	$myfile = "somefile.pdf";
	$myfile = $page->documents->get('name='.$myfile);
	echo $myfile->url;

But I get nothing, not even null...

Thanks for any suggestion

First off, shouldn't the switch to PHP be  "<?php" ??

After that, are you sure your code example is complete? I've never seen that form of if statement used without a switch back out of interpreted PHP straight after it. Have you cropped things out to simplify your example by any chance? After looking at alternative control structures that looks ok.

The other thing to check is that your $myfile string is case-for-case the same as the filename that gets written into the name field as I think the comparison is case sensitive.

Edited by netcarver
  • Like 3
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...