I am using Responsive FileManager extensively as a standalone (not part of a general text editor). I sometimes call it multiple times on one page. However, each time I want it to be restricted to a certain folder—not merely so it defaults to a folder, but so the user can't navigate to any other folders at all.
The only way I have found to restrict a folder in Responsive FileManager is by setting the PHP sesssion variable:
$_SESSION['RF']['subfolder']
However, this is a problem for different folders that need to be there on the same page, and in general it's impractical because the restriction should be specific to the file manager call, not user-specific like a session. Also, I don't need it to be absolutely impossible to navigate to other folders in a secure way, it's OK if someone who knows how to use the browser debugger navigates somewhere else. I merely want to prevent casual users from doing this.
Is there any way to do this with a JS config option, or some other per-call and not per-user way?
Their feature list says:
You can set a subfolder as the root and change the configuration for each user, page or FileManager call.
But I was not able to find a per-call folder restriction in their docs.
Here is a simple tweak to achieve this .
Responisve filemanager calls the dialog.php with some parameters appended like type .What I did is : introduce a new param and put a check for that on the server side to set the uploads path dynamically .
Consider your uploads directory is uploads
and you have user1 , user2 , user3 as sub directories , So , in that case we will be setting the uploads path and current path in the config.php dynamically from the parameters which we will be passing while calling the dialog.php
In the filemanager/config/config.php
Append these lines
if( isset( $_GET['MY_UPLOAD_PATH']))
{
$config['upload_dir'] = $config['upload_dir'] . $_GET['MY_UPLOAD_PATH']."/" ;
$config['current_path'] = $config['current_path'] . $_GET['MY_UPLOAD_PATH']."/" ;
}
In the filemanager/dialog.php
Find this line
$get_params = http_build_query($get_params);
And just before that line add
if(isset($_GET['MY_UPLOAD_PATH'])){
$get_params['MY_UPLOAD_PATH'] = $_GET['MY_UPLOAD_PATH'] ;
}
Now change your variable
$data['file_explorer'] = base_url('assets/resources/filemanager/dialog.php?type=0');
to
$data['file_explorer'] = base_url('assets/resources/filemanager/dialog.php?type=0&MY_UPLOAD_PATH=user1');
Just change the value of the MY_UPLOAD_PATH param and the dialog.php will show only that particular directory .
Related
I am going to deploy this page on an FTP
And I need to find out how I can detect the html file currently being viewed using JavaScript.
If I open the html file, it works just fine with this:
var fileName = location.href.substring(location.href.lastIndexOf("/") +1);
But, if I open it via my localhost adress, it has a null value. So I'm guessing I have to use some other method to extract the current html file name. Or is there a better approach to this?
Note: I am not going to use JQuery or anything like that.
EDIT:
I can get the filename if it isn't my index file.. If it's the index file I get nothing using the above code. Most likely since all I have in my adress bar is the localhost adress of the live-server?
The web deals in URLs, not file names.
Sometimes a URL will include something that looks like a file name, and sometimes that even maps on to a real file name on the server's hard disk.
When you type http://example.com/ then it might map that onto a file called index.html. Or maybe on to index.php. Or maybe it won't touch any file but will just use logic built into the web server application to determine what to respond with.
There's no way to know in the general case.
If your specific case, you know that the path / maps onto index.html, so you can write an explicit mapping in your JavaScript code.
$imgData = base64_encode(file_get_contents('F:\images\home\pic.jpg'));
The above is my local host path. For local host, it is working.
But, how can I get it in my remote server?
I have not worked on FTP. Please guide me.
I need to get the content of the image alone. I don't need to upload the file to remote server.
You seem to be developing on a Windows machine because of the \ directory separator. It is best practice to use forward-slash / as it will work on both Windows and Linux, provided you use relative paths (the path with reference to root directory is called absolute. The path with reference to current directory is called relative). You should aim to use relative paths whenever possible.
Example:
F:/images/home/pic.jpg is an absolute path. Notice I replaced your
backslash \ with a forwardslash /.
http://www.example.com/images/pic.png is an absolute path.
./pic.jpg is a relative path and is equivalent to pic.jpg
../images/pic.jpg ia a relative path (.. means you've exited the current folder, entering the working directory where the images folder is located too).
On your remote (Linux) server, you will have to know the relative path
Let's assume your remote server is a linux/apache server. Maybe you should also tag your question with apache instead of javascript/angular?
You should determine the relative path to your image and use the examples above to rewrite your code to something like this:
$imgData = base64_encode(file_get_contents('../images/home/pic.jpg'));
You can also use an absolute path (http://www.example.com/images/pic.png) but that is not always possible or recommended.
How to find the relative path to your image? There are multiple ways to do that, using PHP, SSH or FTP.
Your FTP software will show you the path to your image if you navigate to it, but you need to adapt it to your working directory path. This image is from Filezilla, an open source FTP client:
In this case, in /home/bg29ll/public_html/food2/images that you see in Filezilla, food2 is your working directory, so you would only need to use:
$imgData = base64_encode(file_get_contents('images/pic.jpg'));
You might also include this line in your php code and run it on your server:
print_r( dirname(__FILE__) );
This will let you know what your absolute path is.
EDIT: to save the image in a database (although I would recommend to upload images to the server and only save the location/name into the DB) you would have to use a blob column type (one of its variations, TINYBLOB, BLOB, MEDIUMBLOB, LONGBLOB). Mediumblob would allow for file sizes up to 16 MB.
CREATE TABLE images (
id INT AUTO_INCREMENT PRIMARY KEY,
mime VARCHAR (255) NOT NULL,
data MEDIUMBLOB NOT NULL
);
You would then use something like this to insert an image in the DB (using PDO):
$blob = fopen($filePath, 'rb');
$sql = "INSERT INTO files(mime,data) VALUES(:mime,:data)";
$stmt = $this->pdo->prepare($sql);
$stmt->bindParam(':mime', $mime);
$stmt->bindParam(':data', $blob, PDO::PARAM_LOB);
$stmt->execute();
I'm currently creating files using drive.makeCopy(Objects[i][1]); where Objects is the name of the various files I want to make from a template.
The script works fine in making these files from a template however after each one has been made I would like to open the new file, hide some sheets in it and to set its permissions. The addresses for the permissions are held in Objects[i][3] but I cannot work out how to open these new files, then make the changes accordingly and then close the file.
I'm assuming by drive.MakeCopy() you are referring to File.MakeCopy(). This is easy, the MakeCopy function returns the File object it has created. You can then set permission this File object using functions such as addEditor(), addViewer(), setSharing(), etc.
So if Objects[i][3] contained the email address of someone who should be able to edit the new file, then you could do:
var new_file = drive.makeCopy(Objects[i][1]);
new_file.addEditor(Objects[i][3]);
You don't really need to "Close" the file after working with it, Apps Script takes care of this automatically.
See:
https://developers.google.com/apps-script/reference/drive/file#addEditor(String)
https://developers.google.com/apps-script/reference/drive/file#setSharing(Access,Permission)
https://developers.google.com/apps-script/reference/drive/file
I'm working on an HTML/javascript app intended to be run locally.
When dealing with img tags, it is possible to set the src attribute to a file name with a relative path and thereby quickly and easily load an image from the app's directory. I would like to use a similar method to retrieve a text file from the app's directory.
I have used TideSDK, but it is less lightweight. And I am aware of HTTP requests, but if I remember correctly only Firefox has taken kindly to my use of this for local file access (although accessing local images with src does not appear to be an issue). I am also aware of the FileReader object; however, my interface requires that I load a file based on the file name and not based on a file-browser selection as with <input type="file">.
Is there some way of accomplishing this type of file access, or am I stuck with the methods mentioned above?
The browser will not permit you to access files like that but you can make javascript files instead of text files like this:
text1.js:
document.write('This is the text I want to show in here.'); //this is the content of the javascript file
Now call it anywhere you like:
<script type="text/javascript" src="text1.js"></script>
There are too many security issues (restrictions) within browsers making many local web-apps impossible to implement so my solution to a similar problem was to move out of browsers and into node-webkit which combines Chromium + Node.js + your scripts, into an executable with full disk I/O.
http://nwjs.io/
[edit] I'm sorry I thought you wanted to do this with TideSDK, I'll let my answer in case you want to give another try to TideSDK [/edit]
I'm not sure if it's what you're looking for but I will try to explain my case.
I've an application which allow the user to save the state of his progress. To do this, I allow him to select a folder, enter a filename and write this file. When the user open the app, he can open the saved file, and get back his progress. So I assume this enhancement is similar of what you are looking for.
In my case, I use the native File Select to allow the user to select a specific save (I'm using CoffeeScript) :
Ti.UI.currentWindow.openFileChooserDialog(_fileSelected, {
title: 'Select a file'
path: Ti.Filesystem.getDocumentsDirectory().nativePath()
multiple: false
})
(related doc http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.UI.UserWindow-method-openFileChooserDialog)
When this step is done I will open the selected file :
if !filePath?
fileToLoad = Ti.Filesystem.getFile(scope.fileSelected.nativePath())
else
fileToLoad = Ti.Filesystem.getFile(filePath)
data = Ti.JSON.parse(fileToLoad.read())
(related doc http://tidesdk.multipart.net/docs/user-dev/generated/#!/api/Ti.Filesystem)
Please note that those snippets are copy/paste from my project and they will not work without the rest of my code but I think it's enough to illustrate you how I manage to open a file, and read his content.
In this case I'm using Ti.JSON.parse because there is only javascript object in these files but in your case you can just get the content. The openFileChooserDialog isn't mandatory, if you already know the file name, or if you get it from another way you can use Ti.Filesystem in your own way.
I'm trying to load an image to a div background using the following file structure in the root.
WebContent --
|
zharaimages --
|
[ItemID] --
|
Image.jpg
This is done by jQuery and the file structure is inside the root. The ItemID folder is dynamic and I have to check whether the path exists using jQuery and if the path is not valid, I should go to a default path to fetch the default image. How can I check the path is valid using jQuery. I'm hoping to this can be done without an ajax call.
Can any one help me on a tutorial or an API I can use for this!
UPDATE
The files are on the server. The concept I have is that I have 100s of item elements & I want to load an image for each item element. The images are saved in the server ( a local host ) and the folder hierarchy is divided using the item ID as shown. What I want to do is check whether the image file exists before appending it to the background of the item element div. Is this possible. This is a web application developed using spring.
In simple way you cannot. It is because JavaScript cannot access folders on server side. The only way you could try to check is to invoke $.get in which you pass url to image and handle error if image does not exist. You cannot try to get only folder because if folder listing is disabled you will always get error
you can bind error handler on your image tag, and if error receive you can load your default image.
$('#imgElementID').error(function() {
$(this).attr('src', 'images/DEFAULT.JPG');
});
without hitting URL you cannot get to know if image exist or not