before upload i will urlencode the filename, so my url is
https://xxx-my.sharepoint.com/_api/v2.0/drive/items/root:/test+test.txt:/content when i upload a file named test test.txt
but this API isn't deal with this.
onedrive api:
https://api.onedrive.com/v1.0/drive/items/root:/test+test.txt:/content can run correctly
how can i keep the accurate file name with PHP
+ is a tricky character in so far as being an encoded form of space. I believe it's technically only legal in the query string, and the expected way to encode the space in the path component is using %20. You'll get the same behavior from both consumer and business if you use the percent encoded version, while as you've found out the + encoding only works as you desire for consumer (although whether it should is obviously debatable).
Office is slowly turning into Google Drive's retarded cousin. Sharepoint or Onedrive doesn't accept spaces or other characters.
Related
I have a site that allows users to create a page based on user input example.com/My Page
The problem is if they create a url like example.com/H & E Photos or example.com/#1 Fan Club
Once php decodes the url, it tries to parse those characters into a hash (or a query string in the case of ?)
In my .htacess I am doing this ([^/]+?)
What is the typical way of handling a situation like this? Ideally, without going to an id system (example.com/131234121). Poor planning on my part :(
EDIT. Talking about PHP here. url is encoded when it hits the server, php decodes before parse regex and url
If you are using PHP to create/handle storing entries for user-entered-URLs then use htmlentities on the string before trying to handle it.
https://www.php.net/manual/en/function.htmlentities.php
https://www.w3schools.com/php/func_string_htmlentities.asp
Apparently, what I was looking for was a rewrite flag.
http://httpd.apache.org/docs/2.2/mod/mod_rewrite.html#rewriteflags
B Escape non-alphanumeric characters before applying the transformation.
This allows you to send percent-encoded strings to the URL without them being decoded beforehand.
So it was actually an apache thing and not PHP. Sorry for the misleading question.
I have a site where users can change their location.
I have all of the available countries stored in a DB and an image for each of these in a folder in the same directory.
However, some countries have special characters and don't display properly or else can't find the image.
The countries in question are:
Côte d'Ivoire
Česká republika
I tried url encoding them so it was like this: %C4%8Cesk%C3%A1+republika
I need a way to store these in the DB in such a way as that they display the name correctly on the site and find the image of the same name.
First of all, see UTF-8 all the way through for all the things you need to do correctly to make non-ASCII characters work in your app in general.
Secondly, it's… tricky… to serve files with non-ASCII file names over the web. 1) You need to ensure that you encode all URLs for these files with percent encoding, as you already seem to do. 2) The web server will take that URL, percent-decode it to a byte string, and then ask the underlying operating/file system to look for a file with a name with that string. This is the tricky part: you won't know exactly what byte string your OS/file system uses to represent that file exactly. You would need to figure that out first, then encode the URL specifically so it will decode exactly to the correct string.
And when you move to a different server, especially if you're moving from Windows to *NIX or vice versa, you can do that all over again since those system do things very differently.
In a nutshell, it's often more hassle than it's worth, and you should store your images with ASCII-only names to avoid all that. Specifically for countries, it'd make a whole lot of sense to use the two-character country codes for the image name (e.g. "cz.jpg").
So AWS converts a space into + for the bucket/file URL. But a filename that already has + in it is encoded as %2B. I am confused how to handle this case.
When the input URL for an application is :
https://s3-us-west-2.amazonaws.com/mybucket/Pul0419_32_a+b.zip
how do I decide whether the file that actually exists is Pul0419_32_a+b.zip or Pul0419_32_a b.zip
AWS enthusiast that I am, I have to concede that the original architects of S3 made an extremely unfortunate error when they decided that + in the path of a URL should be interpreted as if it were equivalent to ASCII 0x20 ("space").
The + character only carries this meaning when part of the query string. In the path, it should have been interpreted literally.
In the path of a correctly encoded and interpreted URL, + is equivalent to %2B.
There is, then, no dependable answer to the question, because of the fundamental flaw that causes S3 to handle correct URLs incorrectly.
Given the fact that if the example URL were used by a browser, S3 would assume those were spaces, your interests would probably be best served by not transforming the URL to use %2B but rather to use it as-is in the interaction with S3... unless practical experience suggests that the original source of these URLs has actually interacted with S3 and did indeed transform them to %2B without storing them for subsequent use with consistent encoding, in which case the argument could be made that they are being provided to you wrong but you may have to transform them anyway, for reasons that may be more political than technical.
But, as it appears you already suspect, the answer is less than straightforward.
I am trying a capture the flag game but I can only enter 50 characters in the url, I have found the name of the file but the name of the file is over 50 chars long (hence why its a challenge), the filename consists of [a-z][0-9] with a .key at the end of the file. I can execute almost all php functions via the url (as long as it doesn't go over 50 chars)
The name is unique with the .key at the end which is why I essentially wanted to use readfile(*.key);
Any suggestions?
note:
CTF is a game penetration testers play to practice their hacking skills...
I have cracked most of the web app along with source code but this is my final hurdle...
the source code its self restricts the url length to 50 characters (you know chars...strlen...)
I dont need to extend the url in the ini file it this is apart of the game.
Use
readfile(md5('th3key').'.key');
It happens that the md5 function will return that string...
I am using a function Rename() (php) to move some images from one folder to another.
The destination folder has special characters in them.
However, when doing this on the server I get the error that the folder isn't found with the name. And in that error, the folder names special characters are replaced with Squares:
Warning: rename(../temp_images/668635375_1.jpg,../ad_images/B�tar/thumbs/668635375_1.jpg)
[function.rename]: No such file or directory in /var/www/etc....
It works on my local machine though (windows xp).
Any ideas?
Troubleshooting tips?
Thanks
I assume this is an encoding problem at some point.
However, using non-ASCII characters in file names is a slippery slope anyway.
I always recommend (since another SO user made me aware of that great and simple idea) that if you can, urlencode() file names and urldecode() them when serving them to the public. This will give you a file name consisting of characters that work on every file system known to me, and can hold any Unicode character.
It is likely an encoding problem: it could be even in the source (in which encoding those "special" characters are written in, in the php source?...), or somewhere else, or both. By "somewhere else" I mean, it could be the right encoding int the string, parsed badly by php, or parsed correctly, but "passed" wrongly from rename() and the underlaying system call (/filesystem) that performs the actual renaming.. In my experience, bad things are likely to occur if you use "special" characters for folders/files that can be read by different systems or accessed through different API... So: do not use "special" characters in folders/files that must be accessible by an http server / php script on a machine system that could be different from the one that "created" the folder/file.
A reading to this could help.