I'm using this file manager for file upload in tinymce.
File Manager
Having some problem with the directory. I'm using tinymce 4.
My filemanager folder is in "localhost/BAD/" directory,
I have a file named about.php which is in "localhost/BAD/admin/" directory. Now I can upload image and see from that about.php file. My settings of tinymce is
**external_filemanager_path:"/BAD/filemanager/",
filemanager_title:"Filemanager" ,
external_plugins: { "filemanager" : "filemanager/plugin.min.js"}**
And my cofig.php file settings are
$base_url="http://localhost";
$upload_dir = '/BAD/source/';
$current_path = '../source/';
$thumbs_base_path = '../thumbs/';
After uploading image and selecting,it shows a path in the image source box as "../source/eng.jpg" and saved that into database.
But I want to access this image from "localhost/BAD/" directory NOT "localhost/BAD/admin/". It starts to find the source file on 'localhost', Not in 'localhost/BAD'
I tried some changes but not working. How can I save the source link as "source/eng.jpg" instead of "../source/eng.jpg" or is there any way to save the image from one directory and access it from previous level directory?
Solution:
In tinymce init:
relative_urls:false,
external_filemanager_path:"/BAD/filemanager/",
filemanager_title:"Filemanager" ,
external_plugins: { "filemanager" : "/BAD/filemanager/plugin.min.js"}
and in config.php
$base_url="http://localhost";
$upload_dir = '/BAD/source/';
$current_path = '../source/';
$thumbs_base_path = '../thumbs/';
Related
When I upload a file in Drupal via the Drupal\file\Plugin\Field\FieldWidget\FileWidget I'd like to get access to the information of the original file, but not the copy.
For example I have a file at the location /home/rnsrk/foo.txt and I upload it via a form element "managed_file".
If I dump the fileUri in the FileWidget::process function with
$files = $element['#files'];
$file = array_shift($files);
dpm($file->getFileUri());
I get only the file info of the file already uploaded and copied to the temp dir: public://2022-11/foo_1.txt.
How do I get the information of the original file from /home/rnsrk/foo.txt?
I have Wordpress Plugin in which I try To display an uploaded image, but I get url like this:
http://localhost/opt/lampp/htdocs/wordpress2/wp-content/plugins/fileuploadplugin/uploads/website-development-banner.jpg
instead of this:
http://localhost/wordpress2/wp-content/plugins/fileuploadplugin/uploads/website-development-banner.jpg
My code is:
<?php
// Configuration - Your Options
$allowed_filetypes = array('.csv','.jpg','.gif','.png','.jpeg'); // These will be the types of file that will pass the validation.
$max_filesize = 524288; // Maximum filesize in BYTES (currently 0.5MB).
define( 'WP_PLUGIN_DIR', $_SERVER['DOCUMENT_ROOT'] . '/wordpress2/wp-content/plugins' );
//$targetpath=WP_PLUGIN_DIR.'/testplugin/documents/'.basename($_FILES["photo"]["name"]);
$upload_path = WP_PLUGIN_DIR.'/fileuploadplugin/uploads/'; // The place the files will be uploaded to (currently a 'files' directory).
//echo $upload_path;exit;
$filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension).
$ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename.
//$targetpath='/uploads'.basename($filename);
// Check if the filetype is allowed, if not DIE and inform the user.
if(!in_array($ext,$allowed_filetypes))
die('The file you attempted to upload is not allowed.');
// Now check the filesize, if it is too large then DIE and inform the user.
if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize)
die('The file you attempted to upload is too large.');
// Check if we can upload to the specified path, if not DIE and inform the user.
if(!is_writable($upload_path))
die('You cannot upload to the specified directory, please CHMOD it to 777.');
// Upload the file to your specified path.
if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename))
echo 'Your file upload was successful, view the file here'; // It worked.
else
echo 'There was an error during the file upload. Please try again.'; // It failed :(.
?>
My Problem is how to remove /opt/lampp/htdocs from $uploadpath to get uploaded image to display correctly?
The problem is that you are using the same path for both uploading and displaying the image.
Path to Upload the image
In your upload code above, you need to use the file system path, as you are doing. The path in your code is:
$upload_path = WP_PLUGIN_DIR.'/fileuploadplugin/uploads/'; // The place the files will be uploaded to (currently a 'files' directory).
This will have a value something like
/home/user/var/www/wp-content/plugins/fileuploadplugin/uploads/
URL to Display the image
The file system path obviously won't work to display the image, so you need to use a URL or a path relative to your website, e.g.
http://www.example.com/wp-content/plugins/fileuploadplugin/uploads/uploadedimage.jpg
To get the URL for your plugins folder, you need to use:
$upload_url = WP_PLUGIN_URL.'/fileuploadplugin/uploads/';
And then you can display the image using that path, e.g.
<img src="/<?php echo $upload_url.$filename; ?>" />
Note:
I have kept WP_PLUGIN_DIR and used WP_PLUGIN_URL in the code above to make it easier for you to see the changes required. However these should not be used directly. Instead you should use the functions provided by WP to get these values: ref Wordpress Codex: Determining Plugin and Content Directories.
I'm creating a plugin in wordpress that uses the wp media uploader to upload files to the site. Problem is that if a file exists with the same name, the name of the file being currently uploaded is appended with a number at the end.
This is a problem if I upload file001.pdf and then the next file is renamed to file0012.pdf instead of file001-2.pdf
It's a problem because then the user may think that is file 12 and not version 2 of file 1.
How can i change that so if there's already a file in the system with the same name, the file being uploaded gets the right rename?
EDIT
So I found out there's a function in wp-includes/functions.php called wp_unique_filename which will check for unique file names and increment until the name is unique. I just need to find a way now to customize that function on the plugin directory.
WordPress provides one hook wp_handle_upload_prefilter as below
function handle_uploadedimage($arr) {
$random_number = md5(rand(10000,99999));
$ext = pathinfo($arr['name'], PATHINFO_EXTENSION);
$arr['name'] = $random_number .'.'.$ext;
return $arr;
}
add_filter('wp_handle_upload_prefilter', 'handle_uploadedimage', 1, 1);
I downloaded the I18n generator package from: http://codex.wordpress.org/I18n_for_WordPress_Developers#Generating_a_POT_file. I want to generate a pot file for my created template now:
php makepot.php /home/mr/workspace/blog/wp-content/themes/myTheme/ de_DE.pot
After executing this command, I get a de_DE.pot with some the WP standard keys in. But my new keys will not be found. But if I add them to the file manually and upload it, they will be translated.
Why doesn't WordPress pick up all my keys?
I have used the poEdit in the following way.
File Menu > New Catalog
Set the language as per your need. Set utf8
Set the paths as . and ..(if you want to place your .mo file at languages folder).
Define the functions from which the strings to take( ie , _, _e, _n, _x, _ex etc).
Now save the file to your template's folder as templateName.po
Now update catalog.
Upon saving the .mo file will be generated in the same folder.
Now rename the .mo file to the specific Locale (for mine bn_BD.mo, for your case de_DE.mo)
I would suggest a few tips from here
I need the .class files (not related to the source files in the project) located in one of the folder inside the project to be exported with JAR too.
If I do export my project with "Deployable plug-ins and fragments" and specify the elements I need to export in build.properties file it does export all I need correctly.
Same I want to do programmatically.
When I create the JAR file with
final JarPackageData jarPackage = jarCreator.create(project, jarLocation);
in create function I set the options like
jarPackage.setJarLocation(jarLocation);
jarPackage.setExportClassFiles(true);
jarPackage.setManifestLocation(manifestFile.getFullPath());
jarPackage.setIncludeDirectoryEntries(true);
jarPackage.setExportWarnings(true);
jarPackage.setGenerateManifest(false);
jarPackage.setOverwrite(true);
jarPackage.setElements(elementsToExport.toArray());
I did check that all the files I need are in the list elementsToExport
final IJarExportRunnable jarExport = jarPackage.createJarExportRunnable(owner.getShell());
try{
owner.getContainer().run(true, true, jarExport);
}
The result is:
It does export the selected folder to the exported JAR file
It does export the text file (for example) located in this folder.
But it does not export the .class files located in this folder.
Please, let me know if you have any glue how to configure JarPackageData to be able to export what ever is in the selected folder!
I am not sure about the particular build system you are using, but Jar files are zip archives, so if you really need to, you can open them up and insert the extra files yourself. Better yet, write a script to do this.