How to get complete file path from typo3 custom extension? - typo3

I am developing custom typo3 extension, i have include file browse option (using kickstarter ) in my plug-ins. I stores only filename. How do i find the complete path of the file?
Generally, typo3 text,text/image elements uploads files into uploads/ directory. How can i do that ?
Thanks.

You could also retrieve the path through the API
$fileName = 'foo.jpg';
$basePath = t3lib_div::getFileAbsFileName('uploads/tx_templavoila/');
$file = $basePath . $fileName;
However, as of TYPO3 6.0 this will become:
$fileName = 'foo.jpg';
$basePath = \TYPO3\CMS\Core\Utility\GeneralUtility::getFileAbsFileName('uploads/tx_templavoila/');
$file = $basePath . $fileName;

Check your ext_emconf.php there should be a configuration entry for creating the necessary directories like in TemplaVoila:
...
'createDirs' => 'uploads/tx_templavoila/',
...
If you need the absolute Filepath you can always use the constant PATH_site, e.g. check if an image exists (assuming $data is filled with the whole row and you are checking for the filename in 'image'):
if(is_file(PATH_site . 'uploads/tx_yourextensionname/' . $data['image'])){
// your code here
}

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.

How to use get the current directory and use wildcard to find any csv file there?

How can I use relative path and relative (wildcard) files in powershell?
I have tried the following but didn't work:
Powershell -c
$file= Get-ChildItem -Filter *.csv
[System.IO.File]::ReadAllText .\$file .replace('Buyer','Alıcı').
replace('Supplier','Tedarikçi').
replace('FI','Banka').
replace('Supplier Reference','Tedarikçi Referansı').
replace('Buyer Program','Alıcı Programı').
replace('Buy Offer','eklif Al').
replace('Payment Obligation Id','Ödeme Yükümlülüğü Kimliği').
replace('Buyer Unique Doc Id','Alıcı Benzersiz Doküman Kimliği').
replace('Trade Date','Ticaret Tarihi').
replace('Due Date','ödeme tarihi').
replace('Maturity Date','Vade Tarihi').
replace('Currency','Para Birimi').
replace('Certified Value','Sertifikalı Değer').
replace('Buyer Payment Amount','Alıcıya Ödeme Tutarı').
replace('Buyer Fee','Alıcı Ücreti').
replace('Supplier Interest Fees','Tedarikçi Faiz Ücretleri').
replace('Supplier Funds Received','Alınan Tedarikçi Fonu')|sc c:\pstest\test2.csv
I want the script to fetch for any csv file in the same directory where the script is being run, any ideas?
I think there is a lot of suggestions how to get path of running script.
Althought I would do that like this:
$dir = $MyInvocation.MyCommand.Path
$dir = $dir.SubString(0, $dir.LastIndexOf("\") + 1)
Then you got path of script execution and what you need is just to call your script.
. $dir"MyScript.ps1"

phpexcel save file to server ubuntu

I'm with a problem I would like to share to see if I can provide help.
PHP Excel use Ubuntu and want guaradar the file generated in a specific folder of my project directory. I understand that looking information is made as follows, but it is not working properly.
My code is as follows:
header('Content-Type: application/vnd.openxmlformats-officedocument.spreadsheetml.sheet');
//header('Content-Disposition: attachment;filename="ReporteSuscriptores.xlsx"');
header('Cache-Control: max-age=0');
$objWriter = PHPExcel_IOFactory::createWriter($objPHPExcel, 'Excel2007');
//$objWriter->save('nameoffile.xls');
$filename = (__DIR__);
$objWriter->save($filename . '/report.xlsx');
Try other alternatives without success as the next block
$objWriter->save('nameoffile.xls');
And I can not save the file generated excel in a specific directory

What does this setup.m file do and what is it for?

What does this setup.m file do?
function setup
%SETUP Adds directories for Metrics to your MATLAB path
%
% Author: Ben Hamner (ben#benhamner.com)
myDir = fileparts(mfilename('fullpath'));
paths = genpath(myDir);
paths = strread(paths,'%s','delimiter',':');
pathsToAdd = [];
for i=1:length(paths)
thisPath = paths{i};
thisPathSplit = strread(thisPath,'%s','delimiter','/');
addThisPath = 1;
% Do not add any directories or files starting with a . or a ~
for j=1:length(thisPathSplit)
thisStr = thisPathSplit{j};
if (~isempty(thisStr)) && ((thisStr(1) == '.') || (thisStr(1) == '~'))
addThisPath = 0;
end
end
if addThisPath ==1
if ~isempty(pathsToAdd)
thisPath = [':' thisPath];
end
pathsToAdd = [pathsToAdd thisPath];
end
end
addpath(pathsToAdd);
savepath;
I understand from the description that it adds directories to Matlab's search path. But which one and why? My Matlab scripts are often scattered with addpath('data') lines. Does this mean I don't have to do that anymore? Your comments are much appreciated.
The file that you are linking is a setup file for the Metrics package - it adds paths to various folders so that you can use Metrics package without setting up the paths manually.
More specifically the setup.m function adds all paths at the level and below where it is located. If you copy this file to any directory and run it - it will add this directory and all its subdirs and subdirs of subdirs etc. (excluding folders starting with . or ~)
But I have a hunch that what you are looking for is this:
http://www.mathworks.com/help/matlab/ref/startup.html
http://www.mathworks.com/help/matlab/ref/matlabrc.html
This is adding the directory that setup.m is located in as well as every sub directory within that directory. fileparts(mfilename('fullpath')) gets the directory that the file exists in, and genpath(myDir); gets all of the subdirectories. Note that this leaves out any directory starting with a '.' or a '~'

From Msi , how to get the list of files packed in each feature?

We have used wix to create Msi. Each Msi will be having 1 or 2 or 3 features such as Appserver feature, Webserver feature and DB server feature.
Now i was asked to get the list of config files presented in each feature.
It is tough to find the list of web.config files associated with each feature through wxs file.
Is it possible find the list of files associated with a feature with particular search pattern?
For ex. Find all the web.config files packed in Appserver feature.
Is there any way easy way ( querying or some other automated script such as powershell) to get the list?
Wix comes with a .NET SDK referred to as the DTF ("deployment tools foundation"). It wraps the windows msi.dll among other things. You can find these .NET Microsoft.Deployment.*.dll assemblies in the SDK subdirectory of the Wix Toolset installation directory. The documentation is in dtf.chm and dtfapi.chm in the doc subdirectory.
As shown in the documentation, you can use this SDK to write code which queries the msi database with SQL. You will be interested in the Feature, FeatureComponents and File tables.
If you haven't explored the internals of an MSI before, you can open it with orca to get a feel for it.
You can do it by making slight modifications to the Get-MsiProperties function described in this PowerShell article.
Please read the original article and create the prescribed comObject.types.ps1xml file.
function global:Get-MsiFeatures {
PARAM (
[Parameter(Mandatory=$true,ValueFromPipelineByPropertyName=$true,HelpMessage="MSI Database Filename",ValueFromPipeline=$true)]
[Alias("Filename","Path","Database","Msi")]
$msiDbName
)
# A quick check to see if the file exist
if(!(Test-Path $msiDbName)){
throw "Could not find " + $msiDbName
}
# Create an empty hashtable to store properties in
$msiFeatures = #{}
# Creating WI object and load MSI database
$wiObject = New-Object -com WindowsInstaller.Installer
$wiDatabase = $wiObject.InvokeMethod("OpenDatabase", (Resolve-Path $msiDbName).Path, 0)
# Open the Property-view
$view = $wiDatabase.InvokeMethod("OpenView", "SELECT * FROM Feature")
$view.InvokeMethod("Execute")
# Loop thru the table
$r = $view.InvokeMethod("Fetch")
while($r -ne $null) {
# Add property and value to hash table
$msiFeatures[$r.InvokeParamProperty("StringData",1)] = $r.InvokeParamProperty("StringData",2)
# Fetch the next row
$r = $view.InvokeMethod("Fetch")
}
$view.InvokeMethod("Close")
# Return the hash table
return $msiFeatures
}