[Up]: Storage API : CopyMove
Script path: /storage/bin/api/copymove.cgi
Description: Copies/Moves a source item (file/folder) to another specifically named target item, or into a target folder, with the target item adopting the source's name. Move is essentially similar to Copy, except that the source item is also deleted. Parameter "move" is used to specify a move or copy operation. If a target file exists, it can be optionally replaced. This however, apply to existing target folders in a different manner. Existing target folder (and their subfolders) are never replaced. It is the files within them that are subjected being replaced.
INPUT (via GET or POST)
Mandatory parameters are: sid, path, tpath
Optional parameters are: move, replace, ofmt
sid | session id of the login user. [mandatory] |
path | path to an item [mandatory] Please refer to [How to specify a path]. path must point to an existing file or folder. e.g. |
tpath | = path to the target item [mandatory] = or path to the folder to contain target item. tpath need not point to an existing file or folder. But the folder (parent) to contain the yet-to-be-created item must itself exist. tpath has the same format as "path" but the
trailing "/" is significant. |
move | = yes Indicates a move operation. By default (when unspecified or when not= "yes"), a copy operation is performed. |
replace | = yes Indicates that files will be replaced (copied over) if the target has files of the same name. The default behavior is not to replace existing files, and return an error. |
ofmt |
= null | json | jsonp null is the default, and the legacy "flat" output format is returned. json means the output format is in JSON format jsonp is like json, but in "pretty" form for easier human readability |
NOTE: File replacement is still subject to other permission to replace that file. E.g. if you don't own the existing file, you are unlikely to be able to replace it even with replace=yes.
NOTE: Replacement of folders does NOT arise during a folder copy/move. That is because it is taken to mean recursive copy/move of files within the folder. Folders (and subfolders) being copied are simply created if they do not exist in the target. If they exist then nothing else is done. What could be replaced are the files in the folder.
OUTPUT (content-type: text/plain)
Successful return:
true <newline>
Equivalent JSON output would look like the following:
{
"status" : true
}
Unsuccessful return:
false <tab> <error message> <newline>
e.g.
false <TAB> Not replacing an existing file.
false <TAB> Permission denied to replace file.
false <TAB> Cannot move a folder into itself.
false <TAB> Permission denied to create folder.
Equivalent JSON output would look like the following:
{
"http_status" : "400 Unable to copy item",
"status" : false,
"errmsg" : "Permission denied to create folder"
}