Is there any function to return the basepath in Zencart? - zen-cart

Is there any function to return the basepath in Zencart?

by HTTP_SERVER and DIR_WS_CATALOG you can get URL
while
by DIR_FS_CATALOG you can get absulute file path
Those are constant defined in configuration file located in includes folder.
There is no need to use any function

Related

How to resolve issue :: file_get_contents(http://localhost:8085/assets/data/test.txt): Failed to open stream: HTTP request failed

By using CodeIgniter 4 framework, I've developed RESTful api and there I need to access file (.json and .txt) to get content. But not able to access php inbuilt function file_get_contents().
For more details, pls check attached screenshot API_curl_file_get_content_error.PNG
And test.txt file is also accessible with same file path. For more details pls check screenshot Input-txt-file-content.png
NOTE : 1) test.txt file and respective directories have full permission.
2) Development environment :
<---->Apache/2.4.47 (Win64) OpenSSL/1.1.1k PHP/8.1.2
<---->Database client version: libmysql - mysqlnd 8.1.2
<---->PHP version: 8.1.2
<---->CodeIgniter 4
Product.php (index method)
<?php
namespace App\Controllers;
use CodeIgniter\RESTful\ResourceController;
class Product extends ResourceController
{
use \CodeIgniter\API\ResponseTrait;
public function index()
{
helper("filesystem");
ini_set('max_execution_time', 300);
$data['msg'] = "Product Index wizard";
$data['status'] = 200;
$file_path = base_url() . '/assets/data/test.txt'; // Read JSON
$json = file_get_contents($file_path, true);
$json_data = json_decode($json, true);
return $this->respond($data);
}
}
Explanation:
Remember that "http://localhost:8085/" most likely points to the document root of the project, which is usually the /public path. So, unless the "assets" folder resides in the /public path, file_get_contents("http://localhost:8085/assets/data/test.txt"); will fail to find the requested server resource.
Solution:
Since your file resource (test.txt) is on the local filesystem,
Instead of:
file_get_contents("http://localhost:8085/assets/data/test.txt");
Use this:
constant ROOTPATH
The path to the project root directory. Just above APPPATH.
file_get_contents(ROOTPATH . "assets/data/test.txt");
Addendum:
I believe you also forgot to add the $json_data output to the returned $data variable in the Product::index resource controller method.

Write text to file in Flutter(Dart)

I want to be able to create a new file and write a string into it. Examples that I can find all seems to pertain to writing to an existing file.
String fileName = 'myFile.txt';
String contents = 'hello';
void writeToFile(String fileName, String contents){
File outFile = File('content://com.android.providers.media.documents/document/document/document_root/' + fileName);
outFile.writeAsString(contents);
}
This results in the following error, as expected
Unhandled Exception: FileSystemException: Cannot open file, path = 'content://com.android.providers.media.documents/document/document/document_root/myFile.txt' (OS Error: No such file or directory, errno = 2)
How can I create a new file in which I can write my contents?
Are you sure that the path exists? writeAsString does create the file if it doesn't exists, but it doesn't create the full folder structure up to the file you're trying to write to. Also, you might not have the rights to write in the path you've specified.
Anyway, you'd better use this plugin to get the folders' path instead of hard-coding them.

How to change path to credentials file (without environment variable)

I currently set path to a credentials file like this:
credentials += Credentials(Path.userHome / ".myfolder" / "my.credentials")
on my local computer this works because Path.userHome results in ~. However, on Jenkins Path.userHome results in /root and I'm unable to create .myfolder under /root at build time because I get a permission denied error.
I am trying to change the path to the credentials file to /home/jenkins/.myfolder/my.credentials. However, when I do
credentials += Credentials("/home/jenkins/.myfolder/my.credentials")
I get a runtime error because apply method for Credentials accepts java.io.File.
Question
How can I pass in /home/jenkins/.myfolder/my.credentials to Credentials?
If it expects a File, then look at the File docs to see how to make one.
credentials += Credentials(new java.io.File("/home/jenkins/.myfolder/my.credentials"))
To expand Brian McCutchon's answer further:
According to SBT's Path.scala source, the Path.userHome returns a java.io.File and Path contains an implicit method implicit def richFile(file: File): RichFile = new RichFile(file) to convert File to RichFile.
And, the slash operator (/) is overloaded for RichFile types to create objects of java.io.File with appended string path.
Hence, if we want to pass a standalone string without a RichFile or File as a path to the Credentials constructor which requires a java.io.File instance as a parameter, we need to specifically create a java.io.File object with the string path, like, File("path/to/file")

does the filePath argument for enterpriseLibrary.ConfigurationSource have to be a non-relative path?

The MSDN documentation for this element says "The path that points to the configuration file. This attribute is required if the configuration source is a file." Ok that's fairly obvious.
I tried just setting it to filePath="enterpriselibrary.config". The file exists in the root of my web app. But when I try to log an exception I get "The configuration file enterpriselibrary.config could not be found." Same thing if I use a relative path "~/enterpriselibrary.config".
So what's the story with this file path, does it have to be a hard path (C:
...\MyApp\enterpriselibrary.config)? Is there some documentation that I'm missing?
This is a known bug in EL 5.0: http://entlib.codeplex.com/workitem/26760
The bug is fixed in EL 5.0 Optional Update 1. There is also a workaround on that bug page (code below). I've used the workaround successfully.
workaround:
code:
[Microsoft.Practices.EnterpriseLibrary.Common.Configuration.ConfigurationElementType(typeof(FileConfigurationSourceElement))]
class FileConfigurationSource : Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSource
{
public FileConfigurationSource(string configurationFilepath)
: base(configurationFilepath)
{
}
}
class FileConfigurationSourceElement : Microsoft.Practices.EnterpriseLibrary.Common.Configuration.FileConfigurationSourceElement
{
public override Microsoft.Practices.EnterpriseLibrary.Common.Configuration.IConfigurationSource CreateSource()
{
string configurationFilepath = System.IO.Path.Combine(AppDomain.CurrentDomain.BaseDirectory, this.FilePath);
return new FileConfigurationSource(configurationFilepath);
}
}
config:
<add name="sourceName" type="YourNamespase.FileConfigurationSource, YourAssembly" filePath ="fileName"/>
The filePath can be relative or absolute. If you specify a relative path then the path is considered relative to the AppDomain.CurrentDomain.BaseDirectory directory. As you discovered you cannot use a root-relative path (~/enterpriselibrary.config).
I'm not sure why your config file is not found; the root of your web application should be the BaseDirectory.
To debug you can check that:
File.Exists(
Path.Combine(AppDomain.CurrentDomain.BaseDirectory,
"enterpriselibrary.config"))
returns true. If it does then Enterprise Library should be able to find the file specified.

how can i get full repository path from SvnClient object?

is there a way to get full path of repository from an svn object?
when i use .path or .pathRepository method i get only relative path of the file
To get the the full uri to a file, use:
SvnInfoEventArgs info;
client.GetInfo(workingCopyPath, out info);
Console.WriteLine(info.Uri);
The repository root:
Console.WriteLine(info.RepositoryRoot);
SvnClient has a method GetRepositoryRoot which gives you the repository root URL. You can then combine this with the relative path of the file you get from .pathRepository.