samba web client - setup connection in php script - php

I have to establish connection with Samba server from my php script in order to download some files into my local server.
Actually its first time I have heard of something like Samba so I Tried to look for a opensource code that I could make use of.
Here it is what I have found: First class - smbclient.php and I tried code posted on the page:
<?php
require_once ('smbclient.php');
$smbc = new smbclient ('//10.0.1.1/example', 'exampleuser', 'examplepassword');
if (!$smbc->get ('path/to/desired/file.txt', '/tmp/localfile.txt'))
{
print "Failed to retrieve file:\n";
print join ("\n", $smbc->get_last_stdout());
}
else
{
print "Transferred file successfully.";
}
?>
Adjusting it into my needs ( server, user, password), all i got is
Failed to retrieve file:
Fatal error: Call to undefined method smbclient::get_last_stdout()
Then I found out about smbwebclient.php project which looks awesome and can be found here.
And this class looks good but the problem is that I have no idea how to use it. Can anyone post it example connection or link to tutorial?

To get files from a samba server, you can try to use a smb wrapper, like the one here but changing the deprecated splits with explodes. Then you can include your php file using this code:
include_once('smb.php');
include( 'smb://user:password#server/folder/file.php');

Reviving old thread but I think I found the solution, the code must have changed since the pot was made on the blog:
print join ("\n", $smbc->get_last_stdout());
should now be
print join ("\n", $smbc->get_last_cmd_stdout());

Related

Start with Couchbase N1QL query in xampp

I was trying to query data from Couchbase server using PHP and N1QL. Please see the code below.
<?php
$cluster = new CouchbaseCluster('127.0.0.1:8091');
$bucket = $cluster->openBucket('travel-sample');
$q = CouchbaseN1qlQuery::fromString("SELECT * FROM `travel-sample`")->consistency(CouchbaseN1qlQuery::REQUEST_PLUS);
$res = $bucket->query($q);
var_dump($res);
?>
Unfortunately, this return NULL. I am usinf Couchbase server 3.0 and PHP SDK. Cam someone help me to correct my N1QL query ?
Regards,
Tismon Varghese
First of all, i was using Couchbase 3.0, so i'm suppose to use N1QL DP3. So i downloaded DP3 from the below URL
https://s3.amazonaws.com/query-dp3/couchbase-query_dev_preview3_x86_win.zip
Extract it, put it on the directory where Couchbase installed (This is not necessary i guess). Extracted directory contains two directories; data and static in addition to a start_turotial.bat and some other files.
Since the .bat file is connected to data directory, we have to change this to get data from Couchbase server. For that, do the following.
Take a backup of the .bat file; right click on it and select 'edit'
change the line cbq-engine -couchbase dir:data to cbq-engine -couchbase http://127.0.0.1:8091/ and save it
Double click on the bat file so that a console window will be popped up (This should be open as long as the query runs). I addition to this, a webpage also opens automatically in your browser; if not, follow the instruction on the popped console window.
..and you are good to go!!!
Regards,
Tismon Varghese.

PHP show_source not working on my server (Altervista)

I am trying to display the PHP source of a file inside a page. I am using show_source function in this way:
<?php
$nomefile = $_REQUEST['nome'];
show_source($nomefile);
?>
When I try this code on my local PC (using USBWebserver v8.6), it works smoothly, displaying the PHP code of the page. But when I try it on my remote webserver (Altervista), I only get an empty page.
I even try to substitute variable $nomefile with name "visite.php", which is the name of a file residing in the same folder, but still I get no result? I try with echo show_source(...), but no result again.
Is there an error in my code? Or maybe show_source is not compatible with all version of PHP? Is there any easy alternative?
Thanks a lot
Giancarlo Perlo - Italy

Get windows title using php doesn't work on browser call

My problem is I need to fetch FOOBAR2000's title because that including information of playing file, so I create a execute file via Win32 API(GetWindowText(), EnumWindows()) and it's working good.
TCHAR SearchText[MAX_LOADSTRING] = _T("foobar2000");
BOOL CALLBACK WorkerProc(HWND hwnd, LPARAM lParam)
{
TCHAR buffer[MAX_TITLESTRING];
GetWindowText(hwnd, buffer, MAX_TITLESTRING);
if(_tcsstr(buffer, SearchText))
{
// find it output something
}
return TRUE;
}
EnumWindows(WorkerProc, NULL);
Output would look like "album artis title .... [foobar2000 v1.1.5]"
I created a php file like test.php, and use exec() to execute it.
exec("foobar.exe");
then in console(cmd) I use command to execute it
php test.php
It's working good too, same output like before.
Now I use browser(firefox) to call this php file(test.php), strange things happened.
The output only foobar2000 v1.1.5, others information gone ...
I think maybe is exec() problem? priority or some limitation, so I use C# to create a COM Object and register it, and rewrite php code
$mydll = new COM("FOOBAR_COMObject.FOOBAR_Class");
echo $mydll->GetFooBarTitle();
still same result, command line OK, but browser Fail.
My question is
Why have 2 different output between command line and browser. I can't figure it out.
How can I get correct output via browser.
or there is a easy way to fetch FOOBAR2000's title?
Does anyone have experience on this problem?
== 2012/11/28 edited ==
follow Enno's opinion, I modify http_control plug-in to add filename info, original json info is "track title".
modify as following
state.cpp line 380 add 1 line
+pb_helper1 = pfc::string_filename(pb_item_ptr->get_path());
pb_helper1x = xml_friendly_string(pb_helper1);
# 1: when firefox opens the php and it gets executed, it the context depends on the user which runs the php-container (apache), this is quite different from the commandline call which gets executed in your context
# 2 and 3: there seems to be more than one way for getting the title: use the foobar-sdk and create a module which simply reads the current title per api, then write your result in an static-html-document inside your http-root-folder OR use the http-client inside the sdk, with it, you do not need a wabserver, even better use a already implemented module: for instance foo_upnp or foo-httpcontrol
Good luck!
If your webserver runs as a service, in windows you need to enable "allow desktop interaction" for the service. Your php script runs as a child of the webserver process when requested via browser.

WordNet access using php

I tried to access the wordnet dictionary as mentioned in: Calling wordnet from php (Wordnet class or API for PHP).
It worked fine through command line. Then I tried to use the php function shell_exec() as below to access the dictionary:
<?php
$output=shell_exec("\Program Files (x86)\WordNet\2.1\bin\wn");
echo $output;
?>
This displays the search option like -ant, -hyp, and so on.i.e it worked fine
But when I tried to add the search option in the above command(as below) it did not work:
<?php
$output=shell_exec("\Program Files (x86)\WordNet\2.1\bin\wn star -synsn");
echo $output;
?>
or even when I gave space in the command like:
$output=shell_exec("\Program Files (x86)\WordNet\2.1\bin\wn ")
it did not work.
Can you please help me what may be the reason for this and any suggestion for the solution?
ok i got the solution now.the problem was because of the spaces between the command.So i handled them as below:
$cmd = '"C:/Program Files (x86)/WordNet/2.1/bin/wn" "home" "-synsn"';
$output=shell_exec($cmd);
thanks to all who responded to my query

Assigning the return value of new by reference is deprecated in

I'm new to PHP and Im playing around with some code to see what i can learn/do. I have a simple little project where I am connecting to a mysql db and displaying the records of a table.
When I put all my code in one file, everything runs smooth, as soon as I try to put a chunk of code in a separte PHP file and use an include or require_once I get the error Assigning the return value of new by reference is deprecated in...PEAR\config.php yadda yadda
I've done some research and I understand that passing an object by reference (&obj) is no longer acceptable in PHP 5, that's fine, but no where in my code do I have an ampersand, and again, it all works fine if it's all in the same .php file. So i figure i might be doing something wrong with my includes or something.
This is the file that 'does the work' that i am calling from my main page with a require_once
include '/config.php';
// Open the database connection
$conn = mysql_connect($dbhost, $dbuser, $dbpass) or die ('Error connecting to mysql');
mysql_select_db($dbname);
//Define and run the query
$query = "SELECT * FROM wp_posts";
$result = mysql_query($query);
echo mysql_error();
//Close the db connection
mysql_close();
echo "<table><tr><td>Post Title</td><td>Post Status</td><td>Post Date</td></tr>";
//Loop through result set and display data
while($tdata=mysql_fetch_array($result))
{
echo "<tr><td>$tdata[post_title]</td><td> $tdata[post_status]</td><td> $tdata[post_date]</td></tr>"; // name class and mark will be printed with one line break
}
echo "</table>";
Anyways, I know my code isn't beautiful, Im still trying to figure it all out. Thanks for any help you can provide.
Additional Information:
Ok, I know I'm a complete noob on this include stuff, and i apologize. Cant quite wrap my head around it all yet. But here's some additional info. Here is the full text of the error message I'm receving (NOTE: My code still runs and my table DOES still display)
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 80
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config.php on line 166
Deprecated: Assigning the return value of new by reference is deprecated in C:\xampp\php\PEAR\Config\Container.php on line 111
Again, I'm using netBeans as my IDE, so in my Netbeans i went to Tools-Options and went to PHP and set C:\xampp\php\PEAR as the Global include path (Whatever the heck that means, but nonetheless it seemed like a good idea).
I guess if my include path is set right (/xampp/php...) then why am I still receiving the error. Grrr. Thanks for all your help guys.
It's the third party library you're using that's causing the problem, it's out of date and is using such things as returning by reference which are no longer considered good practice. You should upgrade the library in question. From what you've written I'm guessing it's this library. http://pear.php.net/package/Config/redirected
Try running pear upgrade config from the shell.
Your include path might be set in the wrong order.
The script seems to prefer the PEAR include directory over the current working directory.
There are several ways to fix this:
1. use absolute includes
For instance, in your case:
include dirname(__FILE__) . 'config.php'; // pre-PHP 5.3
include __DIR__ . 'config.php'; // PHP 5.3
2. change the include path
To read more about this, see this page in the php.net documentation
Open your config.php and go to line 89 and remove the & after =
from:
"$this->container =& new Config_Container('section', 'root');"
to:
"$this->container = new Config_Container('section', 'root');"
Same goes to line 166.
it is simply pear package error which describes the problem about the assignment. so we can normally replace the assignment of
=& with =
in the given line of the error statement.that will solve our problem.
I had similar problem.The solution is change name of your file. config.php gets a file in pear folder not your config file.
Just run C:\xampp\php\pear-update.bat and restart the Apache server (On Windows macchine).
For linux macchine follow the instuctions of GordonM.

Categories