passing variables between pages in Drupal 7 - drupal

I am trying to pass the variables from one page to another in Drupal 7. Since in Drupal 7 we do not create the php file as such the content of the page gets saved as a plain text in DB, no files get created, so GET/POST are out of the solution.
How can I do this?

Content is saved in database, but every content is defined in some content type. And for every content type you can have different template file. Inside that template file you can put your php code reading GET/POST, or what ever.
So, you can use the usual way and read parameters from template, do what ever you want with them.

One way is to use variable_set() to save the value to database and variable_get() to retrieve the value from database.
To save the value:
variable_set('my_variable_unique_id', 'the value to be saved.');
To read the value back:
$myVariable = variable_get('my_variable_unique_id', 'default value in case could not find a saved value for the variable.');

Related

how to retain an input of type file in an JSP page on page reload

How can I retain HTML form field values in JSP after submitting form to Servlet?
I am trying to retain a csv file in the jsp but it looks not possible. I also tried to pass the csv file back to the jsp and send it as a part of form back to the controller but not able to do it. so please suggest a way to retain the csv file or redirect it back to the jsp and be able to use the second time the page reloads
I have done some research and came to a conclusion that it is not possible to retain an input field of type csv file. Please correct me if I am wrong
Answer: As per my knowledge it is not possible as suggested in this https://stackoverflow.com/questions/2598904/how-do-i-keep-form-data-after-submitting-the-form-using-javascript#:~:text=To%20keep%20the%20values%2C%20you,request%20parameters%20into%20the%20fields.&text=You%20can%20use%20cookies%20from,you%20access%20something%20called%20document. answer once the form is submitted the entire page is replaced by response from the server so to retain the csv file values I think we can only use an jQuery.post or jQuery.ajax to send the form data rather than actually submitting the form
If you want to retain any thing that was passed from a jsp and use it in back end, you can do one thing . once passed to the controller, we can read the data of the csv file and set that object in the session using .setAttribute("object name", object). The session object can be fetched and set an object using the following lines of code
HttpSession session = request.getSession();
session.removeAttribute("<object name>");
session.setAttribute("<object name>", object);
and use this object the second time the control moves from jsp to controller by using the getAttribute()
<className> <objectName> = session.getAttribute("<object name>");
and use it as needed.

How to Set a File's Blob Filename?

In a Plone's File content type, which property stores the file's original filename?
I'm using plone.jsonapi.routes to upload files to a plone instance. I can set the id ant the title but I can't set the associated file's filename.
For example, when I upload a file to Plone in the regular way, I can set its id and title, but additionally to that, the original file name is stored somewhere. You can see it here:
objects-essay.pdf - PDF document indicates the name the original file has.
But when I upload it with plone.jsonapi.routes that field is empty. So, I'm trying to figure it out which property stores the name to pass it to the api or to set it by hand.
Thanks.
IIRC, all Archetypes-based content types have a setFilename method that you can use to do this.
On Dexterity-based content types file's content is stored in blobs in the ZODB (instances of NamedBlobFile) and there's a parameter named filename that you can use to set it.
You can see an example of the later in plone.app.contenttypes.

WordPress doesn't recognize meta-data

I have moved a newly built WordPress site from a sub directory in the remote server, to the root directory. I have a couple of custom post types with meta data associated with them, including images metadata (i.e. file & URL). Obviously I had to remove the sub directory from the URL. I did so with a replace SQL query.
Now wordpress doesn't recognize the meta data. When I write the following code:
$img = get_post_meta($post->ID,"mf_logo",true);
var_dump($img);
I get "bool(false)". I have tried to upload a new image, and it is showing. I then manually changed its URL through MySQL and again it wasn't recognized.
It is important to note that the problem only happens with meta data in the form of array, and not with 'normal' meta-data
Your kind help would be most appreciated.
When using meta data (update_post_meta, get_post_meta...) arrays will be automatically serialized in db :
http://codex.wordpress.org/Function_Reference/update_post_meta
A passed array will be serialized into a string.
And you cannot simply replace strings in a serialized array :
$data = array('key'=>'value');
echo serialize($data);
This will output : a:1:{s:3:"key";s:5:"value";}
If you simply replace key or value with a shorter/longer string, il will break the data :
a:1:{s:3:"key";s:5:"replace";} is incorrect
a:1:{s:3:"key";s:7:"replace";} is correct
You can make a batch to handle this.
But prior to this, do you know you can let wordpress in its own directory and make it accessible from root directory, without breaking links ?
Take a look here : http://codex.wordpress.org/Giving_WordPress_Its_Own_Directory#Using_a_pre-existing_subdirectory_install

File upload and read from database

I am using file upload mechanism to upload file for an employee and converting it into byte[] and passing it to varBinary(Max) to store into database.
Now I what I have to do is, if any file is already uploaded for employee, simply read it from table and show file name. I have only one column to store a file and which is of type VarBinary.
Is it possible to get all file information from VarBinary field?
Any other way around, please let me know.
If you're not storing the filename, you can't retrieve it.
(Unless the file itself contains its filename in which case you'd need to parse the blob's contents.)
If the name of the file (and any other data about the file that's not part of the file's byte data) needs to be used later, then you need to save that data as well. I'd recommend adding a column for the file name, perhaps one for its type (mime type or something like that for properly sending it back to the client's browser, etc.) and maybe even one for size so you don't have to calculate that on the fly for each file (useful when displaying a grid of files and not wanting to touch the large blob field in the query that populates the grid).
Try to stay away from using the file name for system-internal identity purposes. It's fine for allowing the users to search for a file by name, select it, etc. But when actually making the request to the server to display the file it's better to use a simple integer primary key from the table to actually identify it. (On a side note, it's probably a good idea to put a unique constraint on the file name column.)
If you also need help displaying the file to the user, you'll probably want to take the approach that's tried and true for displaying images from a database. Basically it involves having a resource (generally an .aspx page, but could just as well be an HttpHandler instead) which accepts the file ID as a query string parameter and outputs the file.
This resource would have no UI (remove everything from the .aspx except the Page directive) and would manually manipulate the response headers (this is where you'd set the content type from the file's type), write the byte stream to the client, and end the response. From the client's perspective, something like ~/MyContent/MyFile.aspx?fileID=123 would be the file. (You can suggest a file name to the browser for saving purposes in the response headers, which you'd probably want to do with the file's stored name.)
There's no shortage of quick tutorials (some several years old, it's been around for a while) on how to do this with images. Just remember that there's essentially no difference from the server's perspective if it's an image or any other kind of file. All the server needs to do is send the type in the response headers and write the file's bytes to the client. How the client handles the file is up to the browser. In the vast majority of cases, the browser will know what to do (display an image, display via a plugin a PDF, save a .doc, etc.).

Get file upload data from post data in ASP.NET

I am looping through the posted values on a form with a view to doing something with them (so don't have access to the controls themselves). This is the process I have to take on this project so that is why I'm doing it this way.
On the form I will have a file upload box but I am not sure how I would upload the file that has been selected from it as I can't just do Control.SaveAs(). When I return the posted value using Request.Form.Item[i] I get the file name I chose but not the full path like I would expect.
Can someone point me in the right direction please?
Thanks.
If you want to manipulate the uploaded files directly, and not through a FileUploader control, you should use the Request.Files collection and not the Request.Form
File Upload controls only pass the file name and the contents. I'm not sure why you would need a folder name, especially since the folder name would be for the client - I can't expect that this would have any value to you since you want to save the file on the server.
As I am unsure of your goals, I would recommend using Server.MapPath("~/Folder") to find a suitable folder to save your uploaded files to

Resources