PyroCMS get the real filesystem path of a uploaded file - pyrocms

How do I get the "real path" (server path) of a file uploaded to the PyroCMS files module.
I need to get the absolute path such as;
"c:\www\pyro\uploads\MYSITE_REF\real_file_name.xlsx"

For this you can simply define a constant like this in constant.php
define('CUSTOM_FILE_PATH',FCPATH.'/uploads/'.SITE_REF.'/files/');
Than you can call it anywhere
$local_file = CUSTOM_FILE_PATH. $my_file_name;

After much searching around, I couldnt find a solid answer, I did find some global variables that seemed to work.
$local_file = FCPATH.'/uploads/'.SITE_REF.'/files/' . $my_file_name;
If anyone has a better way of retrieving this please post it :)

Related

datastage parameter for file directory not working

I am creating an extract from sequential file. I created a parameter with the correct file location and when I try to "View Data", it says it can't find the file. If I hard code the location it finds the file and I am able to "View Data".
example:
#filedirectory# = aaa/bbb/ccc/
so my entry for "File" is #filedirectory#filename.txt and this does not work
however, the following does work
aaa/bbb/ccc/filename.txt
Any ideas what would cause this?
Try using the absolute path. Start with a / and the root directory.
Second point is that the parameter itself does not have "#". The "#" are only needed to reference it - in the Sequential File stage. So name it filedirectory when you define it in the job.
Recommendation:
As filedirectory will probably be used throughout your project I recommand using a ParameteSet.
I had the same issue, and it happened I forgot to include the directory parameter before the file parameter. Hope this information helps someone.

How to reference a file from inside of a gem

What's the correct way to find the absolute path to a file from within a gem? In other words, let's say I'm in gem_install_path/mygem/lib/mygem.rb, and I want the path to gem_install_path/mygem/foo/. What's the correct way to get that?
It is not clear which path you want, but probably one of the following will give you what you want:
Gem.loaded_specs["mygem"].base_dir
Gem.loaded_specs["mygem"].full_gem_path
Gem.loaded_specs["mygem"].gem_dir
Gem.loaded_specs["mygem"].gems_dir

VBA - Creating a dynamic path for an Image

Could someone please help me create a path for an image that I am displaying in the image box? This tool is intended for use of others. Therefore, they will have to download it in their computers and the path to the image will change. I have tried several ways but nothing seems to work. Here is the code:
Me.cmdImage2.Picture = LoadPicture("G:\Pedestrian Bridges\New folder with organization\Visual Basic Tool\Tool\New folder\TRB paper Version\Imagenes Finales\Alternative 2.JPG")
Thanks a lot!!!!!!!!!!
Try thisworkbook.path or activeworkbook.path it will be saved the image in same folder
This is a good question and something I've been recently working on. I will show you a few lines of my code that would be beneficial for you to use as well.
The first potential method you could use would be to implement the IO class's ability to return the path your application is being run from. You can do that by following this example:
MessageBox.Show(IO.Path.Combine(IO.Directory.GetParent(Application.ExecutablePath).FullName, "myimage.jpg"))
Another potential solution would be to use environmental variables.
In order to do this you will need to import the IO class:
using System.IO;
Then you can reference environmental variables like this:
DirectoryInfo dst = new DirectoryInfo(Environment.GetEnvironmentVariable("UserProfile") + #"\Desktop\!#!Desktop_Cleanup\" + s + #"_Desktop\" + category);
Sorters.CopyFiles(src, dst, true, "*."+ extension);
In my example, I'm using the UserProfile enviromental variable that is stored in Windows. Then, knowing where that path leads I am able to add a path to a file system on my desktop that I use for cleaning the desktop. Keep in mind you will need to use the # symbol before strings containing backslashes so they will be read properly and not as escape characters.
Sorters is a class that I made and won't be applicable in your application, but I included that line so you could see a possible implementation of the DirectoryInfo you create.
Hope this helps!

$_SESSION as a local variable

I have a problem with a $_SESSION. I do a POST and i modify the value of $_SESSION['lang'] but this modification is only local (my var_dump($_SESSION); has the good value), but out of this file my variable didn't change.
Do you have any ideas for resolve this problem?
Thanks
I'm not entirely sure I got what you mean by "out of this file". If $_SESSION['lang'] didn't change in files you included in your script then probably you have included those files before you operated the change on $_SESSION['lang']?

Dynamically saving file location

I have an asp.net app and I am trying to save a text file to a folder that changes with each client. How can I write it to save the files to a folder that changes. For example one customer might be C:\inetpub\wwwroot\site1\ another might be C:\inetpub\wwwroot\site2.
Relative paths don't seem to work, and I've tried GetCurrentDirectory but it kept giving me the wrong directory.
Thanks
You should try :
In the *.aspx.cs file :
string currentPath = Server.MapPath("~");
I don't have the tools to test here, but I think the code is right.
Take a look at Path.GetDirectoryName(Request.ServerVariables("SCRIPT_NAME")).
You should add a value to the web.config file which is set to the path where the file is saved.
Then, in you code, retrieve this value from the documentation, and use that path when saving.

Resources