我想知道是否有一个相同的命令将文件夹复制到当前目录,就像使用旧的MS-DOS一样.假设我当前的目录位置是:
/var/www/
Run Code Online (Sandbox Code Playgroud)
我有文件夹和文件:
/home/hope/subfolder/docs/
/home/hope/subfolder/images/
/home/hope/subfolder/.config
/home/hope/subfolder/readme.txt
Run Code Online (Sandbox Code Playgroud)
我知道以下命令:
cp -rT /home/hope/subfolder .
Run Code Online (Sandbox Code Playgroud)
将所有文件(甚至点隐藏文件)和"子文件夹"文件夹中的文件夹复制到当前目录,结果将是:
/var/www/docs/
/var/www/images/
/var/www/.config
/var/www/readme.txt
Run Code Online (Sandbox Code Playgroud)
看起来将源文件夹复制到当前位置的命令是:
cp -rT /home/hope/subfolder ./subfolder
Run Code Online (Sandbox Code Playgroud)
虽然这很好,我发现有时候我会为目的地的复杂文件夹名称犯错,所以有没有办法使用如下命令:
cp -rT /home/hope/subfolder .
Run Code Online (Sandbox Code Playgroud)
或者甚至喜欢这个
cp -rT /home/hope/subfolder /var/www/.
Run Code Online (Sandbox Code Playgroud)
得到以下结果:
/var/www/subfolder/docs/
/var/www/subfolder/images/
/var/www/subfolder/.config
/var/www/subfolder/readme.txt
Run Code Online (Sandbox Code Playgroud)
谢谢.
在定义结构并继承Interface和/或Abstract Class时,哪一个是最佳实践?为什么?这里有两个例子:
以下是[Interface] - > [Abstract Class] - > [Class]的示例
Interface DataInterface
{
public function __construct($connection);
public function connected();
public function get();
}
Abstract class BaseData implements DataInterface
{
protected $connection;
public function __construct($connection)
{
$this->connection = $connection;
}
}
class UserData extends BaseData
{
public function exists()
{
return is_connected($this->connection);
}
public function get()
{
return get_data($this->connection);
}
}
$oUserData = new UserData(new Connection());
Run Code Online (Sandbox Code Playgroud)
这里是没有接口的[Abstract Class] - > [Class]的示例
Abstract class BaseData
{
protected $connection;
public function __construct($connection)
{ …Run Code Online (Sandbox Code Playgroud) 我的.htaccess中有以下代码
<IfModule mod_rewrite.c>
RewriteEngine On
# block text, html and php files in the folder from being accessed directly
RewriteRule ^content/(.*)\.(txt|html|php)$ error [R=301,L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . index.php [L]
</IfModule>
# Prevent file browsing
Options -Indexes
Run Code Online (Sandbox Code Playgroud)
阻止访问内容文件夹中的txt,html,php文件.它工作得很好,如果访问以下URI,它会阻止index.html
mysite.com/content/index.html
Run Code Online (Sandbox Code Playgroud)
但是如果从URI中省略了它,则它不会阻止显示的index.html内容:
mysite.com/content/
Run Code Online (Sandbox Code Playgroud)
如何解决这个问题呢?谢谢.
我有以下命名空间结构与以下类文件
Application
|->App.php
|->Top
|->Start.php
|->Process.php
|->Child
|->Plugin.php
Run Code Online (Sandbox Code Playgroud)
所以我在App.php中声明过
namespace Application;
Run Code Online (Sandbox Code Playgroud)
在Startp.php声明
namespace Application\Top;
Run Code Online (Sandbox Code Playgroud)
在Plugin.php声明
namespace Application\Top\Child;
Run Code Online (Sandbox Code Playgroud)
我看到我可以从App.php中调用Plugin.php类
$object = new Top\Child\Plugin();
Run Code Online (Sandbox Code Playgroud)
如果它是一个子/孙子命名空间,但是如果我想从Plugin.php调用Process.php,这是来自分支的父命名空间呢?是否有类似双点".."的东西来表示命名空间中的上部父目录?我试着打电话
File: Plugin.php
$object = new ..\Process();
Run Code Online (Sandbox Code Playgroud)
它没有用,看起来我只能从根开始一路就好
$object = new \Application\Top\Process()
Run Code Online (Sandbox Code Playgroud)
这是唯一的选择吗?谢谢!
我有以下NGINX重写规则,适用于安装在子文件夹中的PHP脚本:
location /subfolder/ {
if (!-e $request_filename){
rewrite ^/subfolder/(.*) /subfolder/index.php?do=/$1;
}
}
Run Code Online (Sandbox Code Playgroud)
但是Nginx wiki说使用"if"是邪恶的http://wiki.nginx.org/IfIsEvil所以我试过以下
location /subfolder/ {
try_files $uri $uri/ /subfolder/index.php?$args;
}
Run Code Online (Sandbox Code Playgroud)
但它不能替代上面的那个,虽然它适用于WordPress和大多数PHP脚本.如果有办法翻译它使用"try_files"?
谢谢!
我有一个关于传递对象作为参数的问题.当我们传递一个变量时,它会创建一个副本,但看起来像对象总是一个引用指针,这是正确的吗?我已使用以下示例代码进行了测试:
class Base
{
private $var;
function set ($var)
{
$this->var = $var;
}
function show ()
{
echo $this->var, '<br>';
}
}
class Car
{
private $obj;
function __construct($obj)
{
$this->obj = $obj;
}
function set ($var)
{
$this->obj->set($var);
}
function show()
{
$this->obj->show();
}
}
class Bus
{
private $obj;
function __construct($obj)
{
$this->obj = $obj;
}
function set ($var)
{
$this->obj->set($var);
}
function show()
{
$this->obj->show();
}
}
Run Code Online (Sandbox Code Playgroud)
并通过运行
$base = new Base();
$base->set('one');
$base->show(); // one …Run Code Online (Sandbox Code Playgroud) 标准的glob()函数用法就像
$dir = glob("*.txt");
foreach ($dir as $filename) {
echo "$filename size " . filesize($filename) . "\n";
}
Run Code Online (Sandbox Code Playgroud)
使用*作为通配符,但有没有办法否定它来忽略任何以下划线开头的文件,如_something.txt?我试图避免使用preg_match()之类的
$dir = glob("*.txt");
foreach ($dir as $filename) {
if (! preg_match("^_+", $filename, $match) { // doesn't show if 1st char is _
echo "$filename size " . filesize($filename) . "\n";
}
}
Run Code Online (Sandbox Code Playgroud)
但是使用glob()自己的正则表达式来避免首先加载不必要的文件,假设这会更快.
在Amazon EC2实例中,我已按照以下说明删除了默认的MySQL 5.1并安装了MySQL 5.6:
http://sharadchhetri.com/2013/12/26/install-mysql-server-5-6-in-centos-6-x-and-red-hat-6-x-linux/
虽然它已经安装,无法启动mysqld,这里是日志文件:
140112 23:16:53 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
2014-01-12 23:16:54 0 [Warning] TIMESTAMP with implicit DEFAULT value is deprecated. Please use --explicit_defaults_for_timestamp server option (see documentation for more details).
2014-01-12 23:16:54 7601 [Note] Plugin 'FEDERATED' is disabled.
2014-01-12 23:16:54 7601 [Note] InnoDB: The InnoDB memory heap is disabled
2014-01-12 23:16:54 7601 [Note] InnoDB: Mutexes and rw_locks use GCC atomic builtins
2014-01-12 23:16:54 7601 [Note] InnoDB: Compressed tables use zlib 1.2.3
2014-01-12 23:16:54 …Run Code Online (Sandbox Code Playgroud) 我有以下PHP代码
$option = "yes";
Run Code Online (Sandbox Code Playgroud)
和Twig标签
{% if option == "yes" %}
Run Code Online (Sandbox Code Playgroud)
它工作正常,但如果大写则失败
$option = "YES";
Run Code Online (Sandbox Code Playgroud)
我尝试了以下但它不起作用
{% if option == "yes" | lower %}
Run Code Online (Sandbox Code Playgroud)
还有其他方法吗?似乎无法从Twig文档中找到这个,谢谢!
我在Amazon Linux AMI上设置了Nginx.默认的Nginx页面加载正常:
http://ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com/
Run Code Online (Sandbox Code Playgroud)
和nginx.conf中的服务器语句代码是:
server {
listen 80;
#server_name localhost;
server_name ec2-xxx-xxx-xxx-xxx.compute-1.amazonaws.com;
#charset koi8-r;
#access_log /var/log/nginx/host.access.log main;
location / {
root /usr/share/nginx/html;
index index.html index.htm;
}
# redirect server error pages to the static page /40x.html
#
error_page 404 /404.html;
location = /40x.html {
root /usr/share/nginx/html;
}
# redirect server error pages to the static page /50x.html
#
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root /usr/share/nginx/html;
}
}
Run Code Online (Sandbox Code Playgroud)
所以通过将server_name更改为我的域来测试它
server_name samplesite.com;
Run Code Online (Sandbox Code Playgroud)
通过使用浏览器访问它也可以正常工作
http://samplesite.com/
Run Code Online (Sandbox Code Playgroud)
但是当我将"location/root"更改为其他路径时,它不起作用,这里是nginx.conf服务器语句:
server …Run Code Online (Sandbox Code Playgroud) 搜索stackoverflow后,我发现:如何使用PHP从视频URL中检索YouTube视频详细信息?
使用以下代码(我已更改为https而不是http,并添加$ _GET ['v']以从浏览器URL获取视频代码):
function get_youtube($url) {
$youtube = "https://www.youtube.com/oembed?url=". $url ."&format=json";
$curl = curl_init($youtube);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
$return = curl_exec($curl);
curl_close($curl);
return json_decode($return, true);
}
$url = 'https://www.youtube.com/watch?v=' . $_GET['v'];
// Display Data
echo '<pre>';
print_r(get_youtube($url));
echo '</pre>';
Run Code Online (Sandbox Code Playgroud)
我得到了以下结果:
Array
(
[thumbnail_url] => https://i.ytimg.com/vi/AhN5MbTJ0pk/hqdefault.jpg
[version] => 1.0
[type] => video
[html] => <iframe width="480" height="270" src="https://www.youtube.com/embed/AhN5MbTJ0pk?feature=oembed" frameborder="0" allowfullscreen></iframe>
[provider_url] => https://www.youtube.com/
[thumbnail_width] => 480
[width] => 480
[thumbnail_height] => 360
[author_url] => https://www.youtube.com/user/AndreasChoice
[author_name] => AndreasChoice
[title] => …Run Code Online (Sandbox Code Playgroud) php ×6
.htaccess ×2
amazon-ec2 ×2
nginx ×2
apache ×1
cp ×1
html ×1
inheritance ×1
mysql ×1
namespaces ×1
regex ×1
rewrite ×1
scope ×1
symfony ×1
twig ×1
youtube-api ×1