I need to get the name of my image and to add img folder before the name of the figure. I use url() function like below
{{ url('img', 'articles/mypic.jpg') }}
The issue is that I don't get
http://127.0.0.1:8000/img/articles/mypic.jpg
but I get %2F instead of /
http://127.0.0.1:8000/img/articles%2Fmypic.jpg
it works fine in localhost, but does not work properly on my server. I need to reconfigure apache to make it work, and I would like to avoid reconfiguring Apache. Could I avoid encoding / into %2F?
You can use urldecode, but you needn't to decode it for browser will process it well without decode.
php > echo urldecode("http://127.0.0.1:8000/img/articles%2Fmypic.jpg");
http://127.0.0.1:8000/img/articles/mypic.jpg
Related
I'm trying to put a link to my web app in my blade mail template, however the url is showing like this : http://127.0.0.1:8000/.$code->discount->url. instead of a properly built, valid url.
This is how I'm doing it:
Enlace
I also tried with:
Enlace
Second way only gave me a partial url (see bellow), not the full url host and path).
$code->discount->url is /promociones/hamburguesa-de-queso
Just remove the '. .' from around the $code->discount->url:
Enlace
The url() helper is PHP function so wrapping the $code->discount->url in quotes will cause php to see it as a literal string.
I am trying to create a simple web service that will give a result depending on parameters passed.
I would like to use file_get_contents but am having difficulties getting it to work. I have researched many of the other questions relating to the file_get_contents issues but none have been exactly the situation I seem to having.
I have a webpage:
example.com/xdirectory/index.php
I am attempting to get the value of the output of that page using:
file_get_contents(urlencode('https://www.example.com/xdirectory/index.php'));*
That does not work due to some issue with the https. Since the requesting page and the target are both on the same server I try again with a relative path:
file_get_contents(urlencode('../xdirectory/index.php'));
That does work and retrieves the html output of the page as expected.
Now if I try:
file_get_contents(urlencode('../xdirectory/index.php?id=100'));
The html output is (should be): Hello World.
The result retrieved by the command is blank. I check the error log and have an error:
[Fri Dec 04 12:22:54 2015] [error] [client 10.50.0.12] PHP Warning: file_get_contents(../xdirectory/index.php?id=100): failed to open stream: No such file or directory in /var/www/html/inventory/index.php on line 40, referer: https://www.example.com/inventory/index.php
The php.ini has these set:
allow_url_fopen, On local and On master
allow_url_include, On local and On master
Since I can get the content properly using only the url and NOT when using it with parameters I'm guessing that there is an issue with parameters and file_get_contents. I cannot find any notice against using parameters in the documentation so am at a loss and asking for your help.
Additional Notes:
I have tried this using urlencode and not using urlencode. Also, I am not trying to retrieve a file but dynamically created html output depending on parameters passed (just as much of the html output at index.php is dynamically created).
** There are several folks giving me all kind of good suggestions and it has been suggested that I must use the full blown absolute path. I just completed an experiment using file_get_contents to get http://www.duckduckgo.com, that worked, and then with a urlencoded parameter (http://www.duckduckgo.com/?q=php+is+cool)... that worked too.
It was when I tried the secure side of things, https://www.duckduckgo.com that it failed, and, with the same error message in the log as I have been receiving with my other queries.
So, now I have a refined question and I may need to update the question title to reflect it.
Does anyone know how to get a parameterized relative url to work with file_get_contents? (i.e. 'file_get_contents(urlencode('../xdirectory/index.php?id=' . urlencode('100'))); )
Unless you provide a full-blown absolute protocol://host/path-type url to file_get_contents, it WILL assume you're dealing with a local filesystem path.
That means your urlencode() version is wrongly doing
file_get_contents('..%2Fxdirectory%2Findex.php');
and you are HIGHLY unlikely to have a hidden file named ..%2Fetc....
call url with domain, try this
file_get_contents('https://www.example.com/inventory/index.php?id=100');
From reading your comments and additional notes, I think you don't want file_get_contents but you want include.
see How to execute and get content of a .php file in a variable?
Several of these answers give you useful pointers on what it looks like you're trying to achieve.
file_get_contents will return the contents of a file rather than the output of a file, unless it's a URL, but as you seem to have other issues with passing the URI absolutely....
So; you can construct something like:
$_GET['id'] = 100;
//this will pass the variable into the index.php file to use as if it was
// a GET value passed in the URI.
$output = include $_SERVER['DOCUMENT_ROOT']."/file/address/index.php";
unset($_GET['id']);
//$output holds the HTML code as a string,
The above feels hacky trying to incorporate $_GET values into the index.php page, but if you can edit the index.php page you can use plain PHP passed values and also get the output returned with a specific return $output; statement at the end of the included file.
It has been two years since I used PHP so I am just speculating about what I might try in your situation.
Instead of trying fetching the parsed file contents with arguments as a query string, I might try to set the variables directly within the php script and then include it (that is if the framework you use allows this).
To achive this I would use pattern:
ob_start -> set the variable, include the file that uses the variable -> ob_get_contents -> ob_end_clean
It is like opening your terminal and running the php file with arguments.
Anyway, I would not be surprised if there are better ways to achieve the same results. Happy hacking :o)
EDIT:
I like to emphasize that I am just speculating. I don't know if there are any security issues with this approach. You could of course ask and see if anyone knows here on stackoverflow.
EDIT2:
Hmm, scrap what I said last. I would check if you can use argv instead.
'argv' Array of arguments passed to the script. When the script is run on the command line, this gives C-style access to the command line parameters. When called via the GET method, this will contain the query string. http://php.net/manual/en/reserved.variables.server.php
Then you just call your php script locally but without the query mark indicator "?". This way you can use the php interpreter without the server.
This is likely to be the most general solution because you can also use argv for get requests if I am understanding the manual correctly.
In my php script, I'm trying to get the query string ($_SERVER['QUERY_STRING']), append it to another url, and then make a redirect.
If I use the query string without any processing, the new url shows "& amp;" for all the "&'s." Therefore the new url won't work.
I print out the $_SERVER['QUERY_STRING'] and view the page source. It does use "& amp;" for all the "&'s." It doesn't make sense to me and I wonder why. Is it just my server's configuration or PHP's default?
UPDATE: I tested it on MODX CMS using snippet. If running on a regular PHP script, there is no such issue. I guess the problem is with MODX. Any idea?
Just an idea:
If you use TinyMCE to edit stuff, it changes all &'s to &'s - that has been driving me crazy for a lot of times. That happens in snippet calls and can be debugged if you either deactivate the rich text editor for a resource or "quick edit" a resource.
Also good practice: put snippet calls into a chunk. You can call that chunk without risking the syntax of the snippet call.
I have URL like this:
https://domain.com/myscript.php?par=<div>x12.l3 sdfa <div>
But when I make
var_dump($_REQUEST);
at start of my PHP script the parameter isn't listed (key "par" doesn't appear).
The value of par, is some html data including not escaped tags and spaces. Can this be the reason that par doesn't appear in var_dump ?
But when I run exactly the same script with same parameter in localhost:
https://localhost/myscript.php?par=<div>x12.l3 sdfa <div>
it works well.
I compared with tool both urls starting at "myscript.php", they match. So why I don't get the parameter on the server but in localhost?
Is maybe related to PHP configuration? It's the only thing I can think about that could be different.
Thanks in advance.
If you are using this script on a shared hosting server, or a server that someone else configured, then it is likely that there are some security measures in place to protect against GET variables such as the one you posted.
Measures could include mod_security, applicative firewalls and others.
Yes, it was different configuration of the server. In this specific case, allowed length of GET parameters (or URL, not sure).
change https://domain.com/myscript.php?par=<div>x12.l3 sdfa <div>
to https://domain.com/myscript.php?$par=<div>x12.l3 sdfa <div>
but $ before par.
hope this works :)
I'm using CakePHP 2.0.4, PHP 5.3.1, Apache 2.2.14.
For example: the filename is F#7m7~1.gif. It really exists, the path and filename are correct.
Before print HTML tag, I encode it by using urlencode() and the tag goes like:
<img src="/chord/img/chords/F%2523m7~1.gif" alt="F#m7">
But the image is not loading. ('Chord' is a CakePHP Plugin)
I also tried to load it directly on the browser, http://myapp.localhost/chord/img/chords/F%2523m7~1.gif but what I get is: "Missing Controller Error: Chord.ImgController could not be found."
Everything works fine with the file as A~1.gif, but it brokes with filenames such as F#m~1.gif, B(7)~1.gif etc.
Everthing was working ok in pure PHP coded version. Now, it's not working at CakePHP.
Is there anybody have a clue?
You seem to be double-encoding it, the right urlencode for F#7m7~1.gif is F%237m7~1.gif, not F%2523m7~1.gif. Just remove one of them.
The Missing Controller error is just because there is no such file on your server, so Cake thinks you're trying to call an ImgController, within the Chord plugin. Try http://myapp.localhost/chord/img/chords/F%237m7~1.gif, it should work.
Anyway, as #GordonM pointed out, it's best to stick with normal characters for filenames.