setting a destination for uploaded Images in Zend Framework 2 - zend-framework2

i am a little confused about how to set a destination for an uploaded images in zend frameowrk 2
i followed this great tutorial here
and have managed to upload my images. however, i need to upload the image to my public folder. at present i am only able to upload to a folder within the module i am working on.
i.e:
$adapter = new \Zend\File\Transfer\Adapter\Http();
$adapter->setDestination(dirname(__DIR__).'/testImage');
what is the equivalent direname(DIR) that would allow me to set the address to an alternative directory or to the directory in my public folder.
thanks in advance
Paul

Related

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

Struts 2 - Deleting temp files created for file upload

Struts create temp files as part of file upload . I have specified my own location (struts.multipart.saveDir) for creating the temp files. My problem is that the temp files that are getting created are not getting deleted. I was under the impression that the framework would delete the files. Is my understanding correct ? If so then mine is not working as expected. I couldn't get a proper answer any where online . Struts 2 documentation on temp directors (http://struts.apache.org/docs/file-upload.html#FileUpload-TemporaryDirectories) doesn't specify any thing either.
Can some one help figure out
Should struts frame work be deleting temp files it create as part of
upload ?
If the answer for 1 is yes, Is there some thing specific we need to
do ?
Thanks

zendframework 2 how do i upload images to a directory in my view

i have a quick question and would really appropriate some advice.
i am trying to upload images to a directory held in in the view of a module.
the full link to the pic's directory in 'my member's module' is:
C:/Users/test/zend/testingZend2/module/Members/view/members/pics
however, the upload function is held in MembersController :
C:/Users/test/zend/testingZend2/module/Members/src/Members/Controller/membersController
i am able to upload images to the directory. however, i obviously don't want to use the full URL. i want to use a relative link.
i tried the relative links below but they don't work;
Members/view/members/pics
and
../../../view/members/pics
is there for example a function like dirname(DIR) that will provide the first half of the link to the pics directory.
thank you for your help
Paths are relative to the application root, so module/Members/view/members/pics should work.
I would question whether the view folder is a sensible place to store user-uploaded images. Images aren't views, and you won't be able to display these images easily since they are not in a public folder.

Unable to upload image on mvc 4 web application hosted on windows azure

I have developed a web application using ASP.Net MVC 4, then hosted that web application on windows azure (windowsazure.com).
My website is unable to upload image/create file. Should I add some permissions?or how to add these permissions?
Please use Edit question to provide code snippet.
Give the code you've provided, the failing part is most probably the line:
Server.MapPath("~/UploadImages/" + ...);
What you really have to do, is first check whether that folder already exists:
string targetFolder = Server.MapPath("~/UploadImages");
if(!System.IO.Directory.Exists(taretfolder))
{
System.IO.Directory.Create(targetFolder);
}
// then copy the file here
The "problem", if one can say it is a problem at all, is that the server does not have this directory created when you try to put file into it. You have to first the directory before trying to copy files.
And by the way, it is not an "Azure" issue. If you take your code as is and upload it to a hoster (without manually creating or coping the UploadImages folder) you will encounter the very same issues.

access assets from monodroid class library

Is it possible to access files (with build action "AndroidAsset") from a monodroid class library in a monodroid application that references the class library ?
I have created an "Assets" folder in the class lib and added a text file with build action "AndroidAsset", but from the app I could not access it via Assets.Open("file.txt");
I was hoping that the Assets from the class lib and the main application could somehow be "merged"...
No - you a can't access the assets from a class lib - only from the main exe project.
This is similar to the situation with Java Android projects.
One route around this might be to use embedded resources instead - see the answer to this question I asked on xamarin's forums - http://forums.xamarin.com/discussion/186/is-there-a-cross-platform-way-to-include-string-resources-from-class-library-projects - note that I haven't tried this yet
Is it possible to access files (with build action "AndroidAsset") from a monodroid class library in a monodroid application that references the class library ?
Yes. Just access them "as normal" via Context.Assets.Open. There is only one source of assets in the application, so any component can access any and all assets, if they have access to an AssetManager instance.
However, that just takes what you're asking at face-value. Can a Library project use the Context.Assets property? Certainly, if you provide it a Context instance.
But can a Library project provide it's own assets for inclusion into the application? No.
I have created an "Assets" folder in the class lib and added a text file with build action "AndroidAsset", but from the app I could not access it via Assets.Open("file.txt");
Library projects cannot provide assets that will be included in the larger application. Java doesn't support this either, afaik.
Things to remember
1 Build Action is AndroidAsset (Properties)
2 Copy to output directory Do not copy (Properties)
3 Add the file to the Assets folder
var destinationPath = Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), "yourfilename.txt");
using (Stream source = Assets.Open("yourfilename.txt"))
using (var dest = System.IO.File.Create (destinationPath)) {
source.CopyTo (dest);
}
Sometimes this will still fail, monodroid bug. The best thing to do is check to see if the files were included correctly.
Load up Eclipse, in the device browser, you should see your simulator.
Go to the directory data/app/ download the file yourappname.apk
This is just a zip file, so change the extension to .zip and open the
zip archive. And goto the folder /assets and see if the file you are trying
to load is in there.
Also if you try to grab a file off a physical device your testing on, some allow it and other don't. This is easiest to test on the simulator.
It is possible to access the Assets files from a library:
var sourcePath = System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal);
//var files = Directory.GetFiles(sourcePath);
var filePath = Path.Combine(sourcePath, "MyAssetFile.bin");
var content = File.ReadAllBytes(filePath);

Resources