Theme_image() returns nothing - drupal-6

I'm stuck on a roadblock with the simplest of things. In Drupal 6, I'm trying to take a user-entered path to an image and output that image to the page. Here's a bit of code:
$slogan_image = theme('image', $slogan_image_path);
dpm("\$slogan_image_path = '$slogan_image_path'");
dpm("\$slogan_image = '$slogan_image'");
The devel output reads:
$slogan_image_path = '/sites/default/files/images/Family.jpg'
$slogan_image = ''
There is an image at '/sites/default/files/images/Family.jpg'; if I browse to www.mysite.com/sites/default/files/images/Family.jpg, the image will be displayed.
What am I doing wrong? Thanks.

The problem was that my path began with a slash. Drupal paths don't have that initial slash. Drupal being open source, I could look refer to the Drupal 6 api docs and see the code for theme_image included this line:
$url = (url($path) == $path) ? $path : (base_path() . $path);
showed me that Drupal would prepend my path with the base_path(). Executing that code myself, in an Execute PHP page, allowed me to see that theme_image would wind up using //sites/default/files/images/Family.jpg as the $url, clearly an illegal value.
I thought I'd append this short explanation to my trivial problem to help rank beginners see how I debugged it.

Related

%7B and %7D being included in URL query

I'm making an IMBD movie-searching tool with streamlit. I've completed the code, however, my URL query line is not working.
url = f'http://www.omdbapi.com/?t={title}&apikey={APIKEY}'
The code can be seen above:
The issue seems to be when the URL is taken in the braces {} gets changed into their ASCII counterparts instead of being interpreted as taking in the movie title and API key.
The issue can be seen below:
http://www.omdbapi.com/?t=**%7B**title%7D&apikey=%7BAPIKEY%7D
Any advice would be appreciated.
Cheers

Search file in a folder from Onedrive in Azure logic app

I'm having an issue using the OneDrive for Business - List files in folder action.
I'm setting the path of the action to be a parameter received from a previous step via http request.
The value of the path is for example - /Clients/ER/EDI/ERGL/Source
When I hard code the path by selecting it in the OneDrive action, its value at runtime is
"datasets/default/folders/01RODCPVEAQQCC4IDDRBF3JHJW2GR43CXZ" and at design time it is set to
"path":
/datasets/default/folders/#{encodeURIComponent(encodeURIComponent('01RODCPVEAQQCC4IDDRBF3JHJW2GR43CXZ'))}
However, when I try and set the path via parameter, which at design time looks like this
"path":
/datasets/default/folders/#{encodeURIComponent(encodeURIComponent(triggerBody()?['Source']))}"
and is at run time - /datasets/default/folders/%252FClients%252FER%252FEDI%252FERGL%252FSource
it does not work. I'm obviously missing something here, with encoding the path parameter? Any suggestions?
Thanks,
Actually you get the true path, it's just in a encode format. You could find the example , the encodeUriComponent will return the URI-encoded string with escape characters.
So you could decode what you get with this expression:
decodeUriComponent(decodeUriComponent('%252FClients%252FER%252FEDI%252FERGL%252FSource'))
Then you will get the absolute path.
Hope this could help you, if you still have other questions, please let me know.

How to get full path from relative path

I'm trying to access a page from another domain, I can get all other html from php, but the files like images and audio files have relatives paths making them to be looked inside the local server whereas they're on the other server.
I've allowed cross-domain access though PHP from the other page.
header('Access-Control-Allow-Origin: *');
Then I use AJAX load to load that pages' content.
$('#local_div').load('page_to_load_on_side_B #div_on_that_page');
Now, the path looks like this:
../../user/6/535e55ed00978.jpg
But I want it to be full like.
http//:www.siteB.com/user/6/535e55ed00978.jpg
Correction: I have full access to both sites so I need to get the absolute paths from the site where these files are originating.
For this problem would use one of the following:
Server Side Approach
I would create a parameter in server B named for example abspath. When this param is set to 1 the script would start an output buffer ob_start() then before submiting would get ob contents with ob_get_clean() and finally using regular expressions make a replace of all urls for http//:www.siteB.com/. So, the script on server A would look like follows:
<?php
$abspath=(isset($_REQUEST["abspath"])?$_REQUEST["abspath"]:0);
if($abspath==1) ob_start();
// Do page processing (your actual code here)
if($abspath==1)
{
$html=ob_get_clean();
$html=preg_replace("\.\.\/\.\.\/", "http://siteb.com/");
echo $html;
}
?>
So in client side (site A) your ajax call would be:
$('#local_div').load('page_to_load_on_side_B?abspath=1#div_on_that_page');
So when abspath param is set to 1 site B script would replace relative path (note I guessed all paths as ../..) to absolute path. This approach can be improved a lot.
Client Side Approach
This replace would be done in JavaScript locally avoiding changing Server B scripts, . The replacements in Javascript would be the same. If all relative paths starts with ../.. the regex is very simple, so in site A replace $('#local_div').load('page_to_load_on_side_B #div_on_that_page'); for the following (note that I asume all relatives urls starts with ../..):
$.get('page_to_load_on_side_B #div_on_that_page', function(data) {
data=data.replace(/\.\.\/\.\.\//, 'http://siteb.com/');
$('#local_div').html(data);
});
That will do the replacement before setting html to DIV so images will be loaded from absolute URL.
Ensure full CORS access to site B.
The second approach is clean than the first so I guess would use Javascript to do the replacements, both are the same only changes where the replace is done.
There is a PHP function that can make absolute path from relative one.
realpath()
If you mean URL path, simply replace all occurences of "../" and add domain in front.
Try this one:
function getRelativePath($from, $to)
{
// some compatibility fixes for Windows paths
$from = is_dir($from) ? rtrim($from, '\/') . '/' : $from;
$to = is_dir($to) ? rtrim($to, '\/') . '/' : $to;
$from = str_replace('\\', '/', $from);
$to = str_replace('\\', '/', $to);
$from = explode('/', $from);
$to = explode('/', $to);
$relPath = $to;
foreach($from as $depth => $dir) {
// find first non-matching dir
if($dir === $to[$depth]) {
// ignore this directory
array_shift($relPath);
} else {
// get number of remaining dirs to $from
$remaining = count($from) - $depth;
if($remaining > 1) {
// add traversals up to first matching dir
$padLength = (count($relPath) + $remaining - 1) * -1;
$relPath = array_pad($relPath, $padLength, '..');
break;
} else {
$relPath[0] = './' . $relPath[0];
}
}
}
return implode('/', $relPath);
}
Also you can find below solution:
In general, there are 2 solutions to this problem:
1) Use $_SERVER["DOCUMENT_ROOT"] – We can use this variable to make all our includes relative to the server root directory, instead of the current working directory(script’s directory). Then we would use something like this for all our includes:
include($_SERVER["DOCUMENT_ROOT"] . "/dir/script_name.php");
2) Use dirname(FILE) – The FILE constant contains the full path and filename of the script that it is used in. The function dirname() removes the file name from the path, giving us the absolute path of the directory the file is in regardless of which script included it. Using this gives us the option of using relative paths just as we would with any other language, like C/C++. We would prefix all our relative path like this:
include(dirname(__FILE__) . "/dir/script_name.php");
You may also use basename() together with dirname() to find the included scripts name and not just the name of the currently executing script, like this:
script_name = basename(__FILE__);
I personally prefer the second method over the first one, as it gives me more freedom and a better way to create a modular web application.
Note: Remember that there is a difference between using a backslash “\” and a forward (normal) slash “/” under Unix based systems. If you are testing your application on a windows machine and you use these interchangeably, it will work fine. But once you try to move your script to a Unix server it will cause some problems. Backslashes (“\”) are also used in PHP as in Unix, to indicate that the character that follows is a special character. Therefore, be careful not to use these in your path names.

How to encode a PHP file with base64

:)
I have one ridiculously silly question and most of you would like to reffer me to Google right away, but that didn't helped me out within the first hour. I suppose I didn't knew how to look for. I'm having a PHP file and I'd like to have it in base64 yet I can't get it to work anyhow.
1) I encoded my PHP script to base64(and included the PHP tags). It'll look as following : JTNDJTNGcGhwJTIwVGhpcyUyMGlzJTIwdGhlJTIwUEhQJTIwY29kZSUyMCUzRiUzRQ==
This kind of base64 won't execute so I added the PHP tags to it although the encoded file already had it. Still didn't worked out. Removed the tags from the base64 and tried again, but still didn't worked. Then I tried adding the PHP tags and inside of them added :
eval(gzinflate(base64_decode('base64 here')));
Still didn't worked out anyhow. Is anyone here kind enough to tell the kiddo how to run a base64 encoded PHP file properly?
Would be really appreaciated. :)
A simple code:
$source = "JTNDJTNGcGhwJTIwVGhpcyUyMGlzJTIwdGhlJTIwUEhQJTIwY29kZSUyMCUzRiUzRQ==";
$code = base64_decode($source);
eval($code);
or even shorter:
eval(base64_decode("JTNDJTNGcGhwJTIwVGhpcyUyMGlzJTIwdGhlJTIwUEhQJTIwY29kZSUyMCUzRiUzRQ=="));
Do you want to encrypt your code? If so, this is not the right way. Use a accelerator like this one or this one. They will crypt your codes and make them even faster!
If you are going to use base_64 to encode your php file then the encoded text need to seat in between the php tags including the base_64 tag.
Example:
If your code is:
JTNDJTNGcGhwJTIwVGhpcyUyMGlzJTIwdGhlJTIwUEhQJTIwY29kZSUyMCUzRiUzRQ
Then your code should look like:
<?php eval("?>".base64_decode("JTNDJTNGcGhwJTIwVGhpcyUyMGlzJTIwdGhlJTIwUEhQJTIwY29kZSUyMCUzRiUzRQ")); ?>
Basically your basic code will look like this:
<?php eval("?>".base64_decode("Code Goes here")); ?>
There are more simple tools that can give you this option
Check this out: PHP Encoder & Decoder with Domain Lock

Relative path to physical path

<rant>
firstly, I've searched a lot and every single question / blog asks/tells about how to convert physical path to relative, never the other way around. If I've missed that question here, I am sorry.
<rant />
So, I have a directory structure very similar to this:
Root
|....Components
|....Classes
|....Utils
|....FileUtils
|....Assets //this is a folder
|....FileAccess.cs
So, in my FileAccess.cs I just want to read the content of a text file and display it on a page.
in my webpage.aspx.cs I am calling the getFileContent() which is in utils.
so the relative path from FileAccess.cs is Assets\spec.txt
So, how on earth can I access that with code?
this is what I am trying / tried:
//function getFileContent() content..
private const string QuestionnairePath = #"Assets\";
return Server.MapPath(QuestionnairePath + "spec.html");
it ALWAYS throws file not found exception and upon debugging it's not selecting the right folder.
I have even tried this:
private const string QuestionnairePath = #"~Utils\FileUtils\Assets\";
that doesn't work either.
This must be very easy. Just can't figure it out, for the life of me. I hate being a newbie sometimes.
Help please,
Thanks.
ps: Ideally, I would just want to use relative path: Assets\ - wonder if that is possible.

Resources