I am trying to upload some files in local disc C:\ and then read them and display. I have done the following:
at config.php
'route' => 'C:/',
the function that gets the path
function object_get_upload_path($type,$id){
$config = app_db_get_config();
return sprintf($config['route']."uploads/%s/%s/%d/", $_SESSION['active_db'],$type, $id);
}
The problem is that when click the link that gets the path of the file and displays it says:
Not allowed to load local resource: file:///C:/uploads/MARO_KONDI_AL/objekte/48167/laura1e11c10053fd1c6e5dca911103e5c3ae90072.jpg
Basically, if you want to load a file, you have to use the file_get_contents() function. Then you should have a look on the server side for the correct synthax.
I suppose the following one would be correct:
$config['route'] = 'C:/'; // or $_SERVER['DOCUMENT_ROOT']
$display = file_get_contents($config['route'].'uploads/'.$_SESSION['active_db'].'/'.$type.'/'.$id);
Related
I'm trying to download a file stored in my Larval 8 Storage folder. The path is correct I have checked it multiple times. And If I open the path in the search bar. It takes me to the needed image. What am I doing wrong here?
Controller
public function show($_id)
{
$currentUrl = URL::current();
$qrCode = QrCode::format('svg')->size(100)->generate($currentUrl."/".$_id);
$path = storage_path('app/public/'.$_id.'.png');
$asset = Asset::findorFail($_id);
return view('assets::asset',compact('asset', 'qrCode', 'path'));
}
asset.blade.php
<a href="{{storage_path('app\public/'.$asset->_id.'.png')}}" download>{{$qrCode}}</a>
The path of the image is: file:///D:/Facility_Management_System/storage/app/public/6155a180001300004e005e22.png
Which is same path as href="{{storage_path('app\public/'.$asset->_id.'.png')}}"
But, When I click to download the file to download it does nothing.
The download attribute specifies that the target will be downloaded when a user clicks on the hyperlink.
So in this case, if the downloaded file extension is .htm, it means that the response from specified link {{storage_path('app\public/'.$asset->_id.'.png')}} is html, instead of image file(maybe 404).
You need to fix the public url of the image file.
I am trying to move files from my FTP server to a local directory. First I need to find the correct file from the FTP server, as there can be a few hundreds:
//Search for the file.
$fileName= array_filter(Storage::disk('ftp')->files(), function ($file)
{
return preg_match('/('.date("Y-m-d" ,time()).').*.XLSX/', $file);
});
Above finds the correct file. If I dd($fileName), I get this:
My File Name.XLSX
I then try to move that file, to my public disk:
$ftp_file = Storage::disk('ftp')->get($fileName);
$local_file = Storage::disk('public')->move($ftp_file, "moved_file.xlsx");
However above code doesn't work. I get below error:
preg_match() expects parameter 2 to be string, array given
Which I have identified being on below function:
$ftp_file = Storage::disk('ftp')->get($fileName);
What am I doing wrong? How can I move the file, which I am able to find on my FTP server, to my local disk?
Thank you in advance.
As #Loek pointed out, $fileName was an array, and therefore to access it I needed to use:
$ftp_file = Storage::disk('ftp')->get($fileName[0]);
It is giving me the following error,
[text] => Unable to open /home/mehul/www/portal.hsua.com.au/public_html/assets/templates.html
This is the part of code which is causing the problem.
$this->f3->set('const', $constants);
ob_start();
echo \Template::instance()->render('/home/mehul/www/portal.hsua.com.au/public_html/assets/templates.html');
$renderedView = ob_get_clean();
/*foreach ($variables as $varname => $variable) {
$this->f3->clear($varname);
}*/
return $renderedView;
The file might not exist
you're opening the PHP file in your webbrowser PHP file is somewhere located in /var/www delivered by Nginx / Apache. If that's the case, your webserver probably has no access to open a file within your home directory.
I recommend you put the template files next to your PHP file to make sure your webserver has access to it.
The render() methods concatenates the given template $file with all template paths stored in the UI system variable while searching for a valid file. Therefore you either have to specify a relative path or append / as workaround.
Workaround
$f3 = Base::instance();
$f3->concat('UI', ';/');
Source/Reference
The concatination $dir.$file in base.php#L2791 is the culprit. Your error is generated a few lines below.
Update / Example
$f3 = Base::instance();
$f3->concat('UI', ';/'); // Add support for absolute paths.
echo \Template::instance()
->render(__DIR__ . '/template.html');
I have an XML file that I use to create a PHP object. I then want to simply print out the image however I am getting the error 'Not allowed to load local resource'.
To get the image URL I have set a variable
$root = ( __DIR__ );
And then append that to the path in my XML file.
$parseXML = simplexml_load_file('chicken.xml');
$img_url = $parseXML->picture;
$imgg = $root . '/' . $img_url;
This now gives me the current path which is
C:\wamp\www\recipesUpdated/images/MarinoWebsite.jpg
If I copy and paste this into my browser it displays the image but won't work when I echo it in an img src.
Is there a way of getting the path just to
\recipesUpdated/images/MarinoWebsite.jpg
Without the C:\wamp etc ?
Thank you!
You get path to image on your local computer, and browser not allowed to load this path.
Url must contain web server address or be relative
Example:
http://localhost/recipesUpdated/images/MarinoWebsite.jpg
or
/recipesUpdated/images/MarinoWebsite.jpg
For your question, try to set variable $root to empty string or your web server address.
I am using TinyMCE as a WYSIWYG editor.
It is working perfectly, except for the image upload directory. I want each user to have their own directory in the images directory, but I cannot get it to work.
I am passing the user id in the URL and have tried adding the code to get it from the URL in the config.php file where the directories are defined, but the $user_id value remains empty.
Any assistance would be great.
The URL:
http://mydomain.co.za/index.php?user_id=1
The Code:
<?php
$user_id= htmlspecialchars($_GET["user_id"]);
// The URL that points to the upload folder on your site.
// Can be a relative or full URL (include the protocol and domain)
$imageURL = 'http://mydomain.co.za/images/'.$user_id;
// Full upload system path. Make sure you have write permissions to this folder
$uploadPath = '/home/username/public_html/editor/images/'.$user_id;
//We create the directory if it does not exist - you can remove this if you consider it a security risk
if(!is_dir($uploadPath)) {
mkdir($uploadPath,0755,true);
}
//Create thumb directory if doesn't exist
if(!is_dir($uploadPath . 'thumbnail')) {
mkdir($uploadPath . 'thumbnail',0755,true);
}
//Allowed extenstions
$allowedExtensions = array('jpg','gif','jpeg','bmp','tif','png');
//Maximum upload limit
$sizeLimit = 2 * 1024 * 1024;
function isAuth() {
//Perform your own authorization to make sure user is allowed to upload
return true;
}
Is it possible the reason is because it is not in the main php file?
Or Can I get the variable from the URL?
They suggested on their Instructions that I add $userId = Auth::getId(); but id returns an empty value. Plus I have no idea what that command is executing.
PLEASE NOTE:
the file management is being done by TinyMCE Image Uploader & Manager
UPDATE:
By adding the $actual_link = "http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]"; echo $actual_link; I noticed by the time the $_GET command is rung the URL has changed to http://mydomain.co.za/tinymce/plugins/lioniteimages/connector/php/gallery.php, but in the browser URL bar, the URL is still the same with the variable.
Is there anyway to access that URL instead of the one i am getting?
I found the solution.
Simple enough, just created a session and the problem was solved.
I was able to get the variable from the session.