save path in database / or \ - zend-framework2

I want to save the path of an image in my database. I'm developing on a Windows system.
I'm using
setDestination( APPLICATION_PATH . "/userfiles/")
In my database I have a path like the following:
C:\wamp\www\cheyenne\application/userfiles\test...
If I try to use a relative path like \public\covers I get an error like "path or directory does not exist".
I'd prefer the 2nd possibility because the former webserver will be an Apache on a Linux.

It's not a good idea to store in a database the complete path of your picture. You really should consider to use a relative path and build the complete path on render, with a database view... My point of view is that you can or not know where your application will be and how your application will be deploy.
For example, today, you store your image on the same server, tomorow, because of traffic issues, you move all your pictures on a second server dedicated for pictures... if you store the complete path of your pictures, you have to execute a SQL request to change partial path and update your code. If you have juste a relative path, you just have to change your application configuration. This can be done in a config.local file that override your default configuration.
For the backslash... it's normal, you are on Windows. Use on your code the default php global variable DIRECTORY_SEPARATOR instead of "/".

Related

Unrecognized property 'CommType' in connection string using Advantage Data Provider with Entity Framework

I'm trying to set CommType in connection string for Advantage DataBase Server using Entity Framework 5 and Advantage Data Provider in a .NET Web Application.
Connection string is in properties.config file.
I trie to use ads.ini but I don't know where to put it (I try in wwwroot/site/bin but nothing happened)
I need to set this parameters:
RETRY_ADS_CONNECTS = 5
PACKET_SIZE=512
USE_TCP_IP = 1
I can do this whiteout errors, but not using properties.config file.
AdsConnection conn = new AdsConnection("data source=\\\\SERVER1\\DATA; ServerType=remote;TableType=CDX;CommType = TCP_IP");
Any clue about how to solve this? Using ADS.INI or properties.config file, same for me.
Thank you!
Gaston Brave.
You can use the ADS.INI file for this purpose. Where it needs to be located (or how to tell Advantage where to find it) depends on the OS you're using.
From the Advantage Help file topic ADS.INI:
Windows
In order for the ads.ini file to be used, it must be located in the application directory, the Windows directory, the Windows System directory, or the client's search path.
In addition, if an environment variable exists with the name adsini_path, that path will be used to locate the ads.ini file. This can be helpful when you do not want to modify the application’s search path, but still need the ads.ini file to exist in a directory multiple users have rights to (for example on Windows Vista installations). An application can often set the environment variable at run-time before calling any Advantage functions, which avoids the need to set a per-workstation environment variable.
Linux
In order for the ads.ini file to be used, it must be located in the application directory, a directory specified in an environment variable named ADSPATH, in the users home directory, or in the /etc directory. If located in the users home directory the ads.ini file should be named .ads.ini (note the initial "dot").

File Upload/Download Network Root Directory

Using ASP.Net MVC - AdoDB
Im used to upload and download from inside the webserver where I published my files
Server.MapPath("~/UploadedFiles/pdfDocuments/");
and it worked fine.
But now, I want to send them to another root outside the webserver, inside a network directory(shared folder). Need your help because I already tried this:
Server.MapPath(#"\\sharedfolder\UploadedFiles\pdfDocuments\");
Please help me on this. Ill appreciate.
I think you no longer need Server.MapPath at all. Its purpose is to map a relative / virtual path (e.g. an incomplete path such as ~/UploadedFiles/pdfDocuments/ into a full path to a file on disk, e.g. that string might get converted into C:\inetpub\wwwwroot\UploadedFiles\pdfDocuments, for example.
Since you are now using a UNC path (i.e. a path in the form \\server\share), this is already a fully qualified path to a resource. There is no missing information. Therefore in this situation MapPath has no purpose. You can simply remove the line which uses MapPath from your code, and pass your UNC path directly to your upload/download code.
Server.MapPath only works on relative and virtual paths. https://msdn.microsoft.com/en-us/library/ms524632(v=vs.90).aspx
If that is a valid path from you server us it directly.

ASP.NET MVC How to display Image from folder outside webroot

Individual Folder create for each user when they register on website outside the webroot folder.I am able to upload the image and store Image path in database.However,I am unable to display the Image. I am trying to get the path of Image from database using LINQ and display in VIEW but it does not work. I can view only one(from the list of Image)Image when FILESTREAM the image path and retrun using FILESTREAMRESULT
Can anyone please guide me how to achieve it? All I want to do is create folder for each respective user when they register in external folder. Upload Image and display.
Typically, I would keep files in a secure database or within the application's subfolders. But, here's what I would suggest if you really need to access a different folder on the server.
Create a folder on your server's file system ahead of time.
On the server, assign permissions to that folder so that the identity used by your application can access it.
In your code, write code to access the folder and file path.
Hope that helps!
p.s. here's another Q&A on StackOverflow (with some words of warning) in which the second part of the answer is similar to what I suggested.
ASP.NET - Reading and writing to the file-system, outside the application

Can I save the keep the absolute path of a file in database?

In my app I save some photos in sandbox and I keep its absolute path in database. Then I build and run again, I fetch the path and try to get the photo, it says the file doesn't exist.
At last, I found that every time I build and run my app, the path of app is different.
I use NSTemporaryDirectory() to get the temporary path, I run two times and get two results.
/private/var/mobile/Applications/80E09BB5-5FEB-4C27-935E-E29DE7861392/tmp/
/private/var/mobile/Applications/71427100-0DBF-42F0-B6B4-F88F6417292E/tmp/
Is it normal? When user updates my app, will the absolute path change?
If it's normal, should I just keep the relative path in database? Is there some best practice?
It's a very bad idea to store the absolute path in the database as any updates to the app results in the app being stored in a different folder within /private/var/mobile/Applications. During an app update, any files will be migrated across, however any references to them within the database will no longer be valid.
You must therefore always store the filepath relative to some other logical directory; for example the Documents or Caches folder.
This probably means you should store this path as a relative directory within your classes as well, and only resolve to an absolute path when you need to use it.
Finally storing temporary file references is probably a bad idea, as I believe any temporary or cached files can be removed from the filesystem by the O/S whenever it feels like it. Therefore you should store these files in the Documents folder, using the techniques I mentioned above.
You could save the file on server and store its physical path in database. I have built similar applications in past and that is how i used it. Might not be the right way but just a thought.
Is it normal?
Well, what is the meaning of temporary?
When user updates my app, will the absolute path change?
Well, what is the meaning of temporary?
If it's normal, should I just keep the relative path in database?
To do what with it?
Is there some best practice?
Don't use a temporary path for persistent storage. What about the documents folder?

ASP.Net MVC2: Where can I store a file to be able to access it on both my dev box and in production?

I need to store a file, such that my ASP.Net MVC app can access the file, both when I run the website in visual studio, and when the production server is actually running. I don't think that I can do relative pathing on my dev box, because the execution path is something in the System32 folder. I don't know if the same is true on the server, but either way, an absolute path is not an option.
Is there a way that I can refer to this file in code, that will work for both my dev box and my production server?
If you can store the file within your application hierarchy, you can do this:
Server.MapPath("~/path/to/file")
Alternatively, you can get the path of the currently executing assembly like so:
string codeBase = Assembly.GetExecutingAssembly().CodeBase;
UriBuilder uri = new UriBuilder(codeBase);
string path = Uri.UnescapeDataString(uri.Path);
return Path.GetDirectoryName(path);
And construct your relative path from that.
Try a subfolder of the:
Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData))

Resources