Copy/upload file from webserver to standalone mac - php

How can i copy a file/directory with PHP to a MAC machine?
So from
/home/domain/file/file.jpg
to
standalone macmachine directory

You can use the php copy function. read the following article.
function.copy.php
for example:
<?php
copy('/Your/Path/From', '/Your/Path/To');
//OR
copy('http://example.com/your_path', '/Your/Path/To');

copy('/Your/Path/From', '/Your/Path/To');
//OR
copy('http://example.com/your_path', '/Your/Path/To');

Related

How to add user to file permission in Windows Server 2008 R2 with Commad Line

We are using Windows Server 2008 R2 with Plesk. Our website is developed with Php CodeIgniter framework.
We can't read file from subdomain which is uploaded, need to set main domain username to uploaded file, so I can do it with manual but we need to do this with command line so we can exec in Php.
Any help? Thanks.
I found the answer myself, here you go ;)
$file_url = "C:\inetpub\vhosts\domain.com\httpdocs\sub.domain.com\uploads\image.jpg";
$group_username = "example_username";
exec('icacls '.$file_url.' /grant '.$group_username.':f ');
Raw version:
exec("icacls C:\inetpub\vhosts\domain.com\httpdocs\sub.domain.com\image.jpg /grant example_username:f");
That's it. This code will give Full Control.
See more; https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/icacls
Drop a like if it's useful :)

How to copy file over to server using phpseclib (SSH2)

I'd like to know how can I copy a file from localhost to the remote server using the phpseclib library? Which functions within the library would achieve this?
Check this example. if you use the latest version of phpseclib you should use SOURCE_LOCAL_FILE const instead of NET_SFTP_LOCAL_FILE.

PHP SVN Checkout via HTTPS

I want to create an SVN checkout PHP script. All you need is to call a function and pass two parameters: the SVN URL and the output path.
My problem is, that our SVN server can only be accessed via https. But through https, the function doesn't work. Normally the function should return a boolean, but I just get nothing. My first thought was, that I have no permission to write into the output path folder, but I changed the permission to 777 (temporarily). Still doesn't work. I also tried to get some files from another SVN trunk. Behold, this is working. I get the files. Any idea how to get this to work?
Aah, and yes, I set the svn trunk permission to read-write for everyone.
Here's is my code:
<?php
$result = svn_checkout('https://{LINK_TO_SVN_TRUNK}', dirname(__FILE__) . '/tmp');
echo "Result: ".$result;
?>
This is what I have used successfully in the past:
svn_auth_set_parameter(PHP_SVN_AUTH_PARAM_IGNORE_SSL_VERIFY_ERRORS, true);
svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_USERNAME, "username");
svn_auth_set_parameter(SVN_AUTH_PARAM_DEFAULT_PASSWORD, "password");
$changeLog = svn_log($path, $start_revision, $end_revision);
Please confirm if the extension is enabled. php.ini should consist of extension=svn.so or php.d folder should consist svn.ini with the line extension=svn.so. You can check for extension in phpinfo();

How can I get the path of the PHP binary from PHP?

How can I get the binary path of php from PHP?
I saw it in phpinfo(), but I need another method that gets it in Linux and Windows systems.
You can use:
$_SERVER['_']
Also, the predefined constant PHP_BINDIR gives the directory where the PHP executable is found.
Sample on CodePad and Ideone.
It looks like, for security reasons, $_SERVER values are not exposed.
Linux Only
Use the "which" command to find php.
$phpPath = exec("which php");
Note this does not guarantee the same php executable that your web server may be using, but rather the first instance that was found while looking through the paths.
A method using environment variables, assuming the php executable is in the system path.
function getPHPExecutableFromPath() {
$paths = explode(PATH_SEPARATOR, getenv('PATH'));
foreach ($paths as $path) {
// We need this for XAMPP (Windows)
if (strstr($path, 'php.exe') && isset($_SERVER["WINDIR"]) && file_exists($path) && is_file($path)) {
return $path;
}
else {
$php_executable = $path . DIRECTORY_SEPARATOR . "php" . (isset($_SERVER["WINDIR"]) ? ".exe" : "");
if (file_exists($php_executable) && is_file($php_executable)) {
return $php_executable;
}
}
}
return FALSE; // Not found
}
Maybe the best solution is in the Symfony process component:
PhpExecutableFinder.php and ExecutableFinder.php. In use:
<?php
use Symfony\Component\Process\PhpExecutableFinder;
$phpFinder = new PhpExecutableFinder;
if (!$phpPath = $phpFinder->find()) {
throw new \Exception('The php executable could not be found, add it to your PATH environment variable and try again');
}
return $phpPath;
In Windows, using WAMP, you can use the ini variable - extension_dir - as it is placed in the PHP folder.
Like this:
echo str_replace('ext/', 'php.exe', ini_get('extension_dir'));
Normally, in a simple default PHP installation under Windows, the php.ini file is located and loaded from the same directory of the PHP binary.
To simplify, Windows users:
echo dirname(php_ini_loaded_file()).DIRECTORY_SEPARATOR.'php.exe';
VoilĂ !
Of course, if you are using multiple .ini files, it may not work if the files are not into the same PHP binary directory. BTW, this may solve to most of cases. Windows developers running PHP from local development environment.
As of PHP 5.4 you can simply use the PHP_BINARY reserved constant.
It's very easy!
var_dump(getenv('PHPBIN'));
But it works only on Windows, so we should use this answer.
How did I get this? I just typed echo echo phpinfo(); and searched the php path there. Just see here:
Then I just getting it here: php getenv and ... you see the result.
For Windows and XAMPP:
$php = getenv('PHPRC') . '/php.exe';
if(is_file($expected)){
return $php;
}

How to call ASP.NET .dll file from a PHP script?

Do you know how can I call an ASP.NET .dll file from a PHP script?
Thanks!
You use the DOTNET extension.
First off, you need to be running this on Windows. If you are on linux, then I would look at using something like Facebooks Thrift.
If you are on windows and depending on which build of windows you are using you may need to uncomment the com extension in your php.ini
<?php
$stack = new DOTNET("mscorlib", "System.Collections.Stack");
$stack->Push(".Net");
$stack->Push("Hello ");
echo $stack->Pop() . $stack->Pop();
?>
Here are a list of Windows Specific functions

Categories