I would like to use Paw to send form files, that I can catch from my PHP script with the $_FILES global variable.
The File body option sends a file, but it is not encapsulated in a form structure and PHP cannot treat it.
How can I do that ?
Set your request to POST, which is likely to be the method you want to use
Go to the body tab, and pick Multipart on the left column
Enter the expected file name as "Part Name" (the key you want to get in your PHP $_FILES global)
In the Value field of the Multipart editor, right-click and pick File > File Content
Click on the File token, and you'll be able to pick or drag-and-drop a file
Press Cmd + R (or Cmd + Enter) to send the request!
Related
I am new to drupal 7, I am trying to create hook_file_presave / hook_file_validate / hook_field_validate function, That checks if pdf file that is uploaded on site is not password protected.
I can easily check using php if file is password protected. But when I display error message, it only displays error message also uploads file. I think i am not using right hook.
function simpletest_file_presave($destination){
// here is my logic
drupal_set_message(t('file is encrypted >>>>>>>> '. $filename), 'error');
return;
}
Here you can see file shouldn't be uploaded buit its there with remove button.
It's been a while since I've touched Drupal, but I first thought about hook_file_validate().
But as explained here you could implement hook_form_FORM_ID_alter() in order to add your own file upload validator and then return an array of errors to display.
Important: When you use the t() function to translate your message don't append the filename to your string because this will create multiple translated strings, one for each uploaded file so it will never be translated as it will always vary. To avoid that, use a placeholder and pass the filename as string parameter, like this:
$error_message = t(
'The file "#filename" is encrypted! Please upload a PDF without password protection.',
['#filename' => $filename_without_path]
);
See the API documentation for the t() and format_string() functions
I made a program to create Jobs field Tickets, and i want to add a option in the same form that open MSPaint or other program in a blank page using the ticket number as a file name, so, whoever is creating the Ticket can hand draw anything.
Create an empty template image file with appropriate dimensions and file type at a constant path
use FileCopy to copy it to your desired path & file name
use Shell to launch a mspaint.exe command-line with your file name as parameter.
I am using Ext.js4 and Java servlets. When the user clicks a button on a panel, I execute a Servlet which in turn executes another application, which produces a log file in .txt format. I know the servlet and the other application are being executed. I want the servlet to return the contents of the .txt file, which Ext.js should in turn display as straight text on a separate "Log" tab. Do I need a store and model for something like this? Note that the data returned by the servlet is just text, not JSON or HTML, and special characters (which would preclude the use of JSON or HTML) may be included in that text. Thanks in advance.
No, you don't need a store and model for this.
I would write a servlet that simply returns the contents of the .txt file.
Then use the Ext.Ajax class to create a request to this servlet and save the text as a variable.
Then you can just do: logTab.update(theText) to fill your tab with the contents of the .txt file (where logTab is your tab you want updated).
For example:
Ext.Ajax.request({
url: '../textServlet',
success: function(response){
var theText = response.responseText;
logTab.update(theText); // or however you define your tab
}
});
I have a asp.net application which reads and updates and xml file in my file system.I do have the options edit and save.As of now it serves my purpose but what if the user edits the values and saves but for some reason he wants to restore the old values to the xml file.I want to
have an option called reset which will get the old values of the xml file incase the user wants to get back to the default values.How do i create a back up to the original file and how do i call that xml file ??? Can any one suggest whether i am in right path or not?
I am using Linq-to xml here .
Keep a copy of the original XML file. Call it xml_file.bk and when the user clicks "reset" delete the current XML file and make a copy of XML_File.bk to the real name with the .xml extension.
You can use File.Move(sourcefile, destinationFile) to make a copy of the original.
File.Move documentation.
I have to create a tab delimited txt file from a query.
I want to call an HttpHandler that returns my txt file as a stream, I don't want to create the file phisically.
1st question:
what is the best practice to create the tab delimited txt file from a query result?
I have to fetch all rows and create the file manually?
2nd question:
How to set a timeout for the HttpHandler that creates the file?
Thanks for your time.
I would create a plain old http output stream and change the content type to 'text/plain' which means that you don't need to physically create the file on the web server, and if you add the content-disposition header to the output and specify that it has an attachment called something like 'report.txt' the user will be prompted to Open or Save the content, rather than just viewing it in the browser like a normal web page.
You can use the Server.ScriptTimeout = x to set the script timeout by gaining access to the current HttpContext object
Hope this helps