Posts Tagged PHP
Styling or modifying drupal primary and secondary tabs like drupal.org
If you want your drupal website’s primary and secondary tabs in same style like drupal.org have in “bluebeach” theme. (See the below graphic.)

Drupal styled tab
Then you have to create a wrapper for tabs so you can put the rounded corner images on both side of tabs. like this
<span class=”a”><span class=”b”>Tab Title</span></span>
But the default “garland” theme does not provide this wrapper. So, you have to put this wrapper by customizing theme. Here I am just illustrating the code that you need to create wrapper around the tabs. After that you need to put the necessary style in your CSS files.
You need to change the “theme_menu_item_link()” to put these wrappers in tab. I am using the code of Drupal 6.9 in this example but I think this approach will work in all versions of Drupal by little tweak.
Existing code:
<?php function theme_menu_item_link($link) { if (empty($link['localized_options'])) { $link['localized_options'] = array(); } return l($link['title'], $link['href'], $link['localized_options']); } ?>
New code (With changes required)
<?php function theme_menu_item_link($link) { if (empty($link['localized_options'])) { $link['localized_options'] = array(); } if ($link['tab']) { $link['title'] = ‘<span class=”a”><span class=”b”>’ . $link['title'] . ‘</span></span>’; $link['localized_options'] = $link['localized_options'] + array(’html’ => TRUE); } return l($link['title'], $link['href'], $link['localized_options']); } ?>
How upload file using cURL?
Here I am giving an example of how you can upload file using cURL in PHP.
Code:
<?php $request_url = ‘http://www.akchauhan.com/test.php’; $post_params['name'] = urlencode(’Test User’); $post_params['file'] = ‘@’.'demo/testfile.txt’; $post_params['submit'] = urlencode(’submit’); $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $request_url); curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $post_params); $result = curl_exec($ch); curl_close($ch); ?>
Here we have first initialized the new CURL session using “curl_init” function. Then we have set few curl options for CURL session.
CURLOPT_URL: URL to fetch.
CURLOPT_POST: TRUE to regular HTML POST.
CURLOPT_RETURNTRANSFER: TRUE to return the transfer as a string of the return value of “curl_exec” instead of outputting it out directly.
CURLOPT_POSTFIELDS: The full data to post in a HTTP “POST” operation.
You can also set more options as per your requirement but these are the minimum require options for file upload. You can find more information about these options in PHP manual.
Then execute the CURL session through “curl_exec” function. This function will return the output of request.
Here the tricky part is ‘@’ symbol before file name. CURL automatically upload the give file to server or requested URL when it find the ‘@’ symbol in starting of file name.
Note: If you try this code on localhost under windows operating system then you might get the error message “CURL is failed to created the post data”. But this code is work fine under Linux environment. So, try this on your server.
The requested file “test.php” consider this request as simple POST FROM request. Like if you use this form for request.
<form method=”post” action=”test.php” enctype=”multipart/form-data”> <input type=”text” name=”name” value=”Test User” /> <input type=”file” name=”file” /> <input type=”submit” name=”submit” value=”submit” /> </form>