I am using Html file Api to read a file.Using i read it.it will show a browse button and select the file and read ..in this manner.
But instead of the above i want to manually set one default file to read every time.With out changing the code how can it possible.
In file Api it read the file from browser using ----
function resetFileUploader() {
getElem("uploader").innerHTML= '<input id="filechooser" type="file" />';
getElem("filechooser").addEventListener("change", getFile, false);
}
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 am new to TXTextControl. I am currently using TXTextControl 24 version.
I need to upload an image from local system (Client system) into the document.
I have written the JS for uploading the file through .
The JS makes a call to backend service which gets the file, Add it to a new RTF file and respond back to JS. The RTF file is then loaded to the Selection.Load of TextControl.
Code: add image to RTF
TXTextControl.ServerTextControl tx = new TXTextControl.ServerTextControl();
tx.Create();
tx.Images.Add(myImage, tx.InputPosition.Page, new Point(100, 100), TXTextControl.ImageInsertionMode.FixedOnPage);
string sHTML;
tx.Save(out sHTML, TXTextControl.StringStreamType.RichTextFormat);
The server responds back with with message "The Module for displaying image is obsolete. (01-0803)"
How can I add the Image into the TXTextControl Document ?
I recently pull a project from GitHub that included a compile-soy task in its build.xml. The task uses SoyToJsSrcCompiler.jar to compile a couple of soy files into javascript. The project included the target directory so I could see that the compiled files contain code like this:
jive.fbldr.soy.attachments = function(opt_data, opt_sb) {
var output = opt_sb || new soy.StringBuilder();
output.append('<div class="fbldr-attachments"><div class="fbldr-attach-head"><p>Use the following form to upload file attachments and, optionally, include a variable to reference the uploaded file in the form\'s HTML source.</p><p>Multiple files may be attached, but only one at a time. Click "Finished" when all files have been attached.</p></div><div class="fbldr-attach-field"><label>Link to HTML Variable (optional) : </label></div><div class="fbldr-attach-field"><select id="fbldr-attach-link"><option value="" selected="selected">Select HTML variable...</option>');
var optionList34 = opt_data.variables;
var optionListLen34 = optionList34.length;
When I run the same task without any code changes, the resulting compiled keeps replacing opt_sb with opt_ignored and stripped out all references to soy.StringBuilder. I ran "java -jar lib/SoyToJsSrcCompiler.jar --outputPathFormat target/soy2/fbldr.soy templates/fbldr.soy" by hand instead of using the build.xml. I get the same result.
jive.fbldr.soy.attachments = function(opt_data, opt_ignored) {
var output = '<div class="fbldr-attachments"><div class="fbldr-attach-head"><p>Use the following form to upload file attachments and, optionally, include a variable to reference the uploaded file in the form\'s HTML source.</p><p>Multiple files may be attached, but only one at a time. Click "Finished" when all files have been attached.</p></div><div class="fbldr-attach-field"><label>Link to HTML Variable (optional) : </label></div><div class="fbldr-attach-field"><select id="fbldr-attach-link"><option value="" selected="selected">Select HTML variable...</option>';
var optionList4 = opt_data.variables;
var optionListLen4 = optionList4.length;
From all the Closure Templates documentation I've read, it is expected the output will use StringBuilder. I cannot figure out why my call keeps generating output that ignores the StringBuilder. Would someone happen to know what could cause this?
StringBuilder was appropriate for Internet Explorer 7 and earlier browsers. For modern browsers simple string concatenation is more efficient and Closure Templates was changed to make that mode the default mode (as an added bonus, the code is smaller). It sounds like the documentation has not been updated to reflect this change.
If for compatibility reasons your require StringBuilder you can set this option on the command-line using --codeStyle stringbuilder
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);