Php 如何通过站点管理端的按钮删除yii资产
我正在我的项目中使用yii1。 运行项目时,yii会在项目的资产文件夹中自动创建资产文件。有时会产生一些问题。 我想知道,我如何设置一个按钮,在网站管理端删除所有的资产文件时,点击该按钮Php 如何通过站点管理端的按钮删除yii资产,php,yii,Php,Yii,我正在我的项目中使用yii1。 运行项目时,yii会在项目的资产文件夹中自动创建资产文件。有时会产生一些问题。 我想知道,我如何设置一个按钮,在网站管理端删除所有的资产文件时,点击该按钮 谢谢这是您想要做的: 在jquery中,您需要调用一个请求,该请求将在按钮单击事件中调用一个php文件 Html+Jquery <div id='result'></div> <button>Delete</delete> <script src="htt
谢谢这是您想要做的: 在jquery中,您需要调用一个请求,该请求将在按钮单击事件中调用一个php文件 Html+Jquery
<div id='result'></div>
<button>Delete</delete>
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script>
$("button").click(function() {
$.ajax({
type: "POST",
url : "request.php",
data: {
'fire': 'true'
},
success : function(data)
{
console.log(data);
$("#result").html(data);
}
},"json");
})
</script>
注意:
我不知道。由于OP想知道在php的简单jquery调用中实现它的示例,所以我编写了这个简单调用
Points to be noted
以下是您想要做的: 在jquery中,您需要调用一个请求,该请求将在按钮单击事件中调用一个php文件 Html+Jquery
<div id='result'></div>
<button>Delete</delete>
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script>
$("button").click(function() {
$.ajax({
type: "POST",
url : "request.php",
data: {
'fire': 'true'
},
success : function(data)
{
console.log(data);
$("#result").html(data);
}
},"json");
})
</script>
注意:
我不知道。由于OP想知道在php的简单jquery调用中实现它的示例,所以我编写了这个简单调用
Points to be noted
以下是您想要做的: 在jquery中,您需要调用一个请求,该请求将在按钮单击事件中调用一个php文件 Html+Jquery
<div id='result'></div>
<button>Delete</delete>
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script>
$("button").click(function() {
$.ajax({
type: "POST",
url : "request.php",
data: {
'fire': 'true'
},
success : function(data)
{
console.log(data);
$("#result").html(data);
}
},"json");
})
</script>
注意:
我不知道。由于OP想知道在php的简单jquery调用中实现它的示例,所以我编写了这个简单调用
Points to be noted
以下是您想要做的: 在jquery中,您需要调用一个请求,该请求将在按钮单击事件中调用一个php文件 Html+Jquery
<div id='result'></div>
<button>Delete</delete>
<script src="http://code.jquery.com/jquery-1.7.2.js"></script>
<script>
$("button").click(function() {
$.ajax({
type: "POST",
url : "request.php",
data: {
'fire': 'true'
},
success : function(data)
{
console.log(data);
$("#result").html(data);
}
},"json");
})
</script>
注意:
我不知道。由于OP想知道在php的简单jquery调用中实现它的示例,所以我编写了这个简单调用
Points to be noted
以下是清除yii 1.1应用程序通用结构的资产文件夹的简单功能:
public static function removeAssets()
{
$dir = realpath(Yii::app()->basePath.DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."assets");
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it,
RecursiveIteratorIterator::CHILD_FIRST);
foreach($files as $file) {
if ($file->getFilename() === '.' || $file->getFilename() === '..') {
continue;
}
if ($file->isDir()){
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
}
}
return true;
}
@斯图:
为什么要删除资产文件夹中的任何内容?这一切都是由Yii管理的,不应该真的需要更改其中的任何内容?
例如,如果缓存了资产,并且您对已发布的脚本进行了一些更改,则此功能有时非常有用。以下是清除yii 1.1应用程序通用结构的资产文件夹的简单功能:
public static function removeAssets()
{
$dir = realpath(Yii::app()->basePath.DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."assets");
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it,
RecursiveIteratorIterator::CHILD_FIRST);
foreach($files as $file) {
if ($file->getFilename() === '.' || $file->getFilename() === '..') {
continue;
}
if ($file->isDir()){
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
}
}
return true;
}
@斯图:
为什么要删除资产文件夹中的任何内容?这一切都是由Yii管理的,不应该真的需要更改其中的任何内容?
例如,如果缓存了资产,并且您对已发布的脚本进行了一些更改,则此功能有时非常有用。以下是清除yii 1.1应用程序通用结构的资产文件夹的简单功能:
public static function removeAssets()
{
$dir = realpath(Yii::app()->basePath.DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."assets");
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it,
RecursiveIteratorIterator::CHILD_FIRST);
foreach($files as $file) {
if ($file->getFilename() === '.' || $file->getFilename() === '..') {
continue;
}
if ($file->isDir()){
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
}
}
return true;
}
@斯图:
为什么要删除资产文件夹中的任何内容?这一切都是由Yii管理的,不应该真的需要更改其中的任何内容?
例如,如果缓存了资产,并且您对已发布的脚本进行了一些更改,则此功能有时非常有用。以下是清除yii 1.1应用程序通用结构的资产文件夹的简单功能:
public static function removeAssets()
{
$dir = realpath(Yii::app()->basePath.DIRECTORY_SEPARATOR."..".DIRECTORY_SEPARATOR."assets");
$it = new RecursiveDirectoryIterator($dir, RecursiveDirectoryIterator::SKIP_DOTS);
$files = new RecursiveIteratorIterator($it,
RecursiveIteratorIterator::CHILD_FIRST);
foreach($files as $file) {
if ($file->getFilename() === '.' || $file->getFilename() === '..') {
continue;
}
if ($file->isDir()){
rmdir($file->getRealPath());
} else {
unlink($file->getRealPath());
}
}
return true;
}
@斯图:
为什么要删除资产文件夹中的任何内容?这一切都是由Yii管理的,不应该真的需要更改其中的任何内容?
例如,如果缓存了资产,并且您对已发布的脚本进行了一些更改,则此命令有时非常有用。如果您拥有Linux服务器,并且PHP具有运行shell命令的权限,则可以尝试使用一行命令递归删除资产中的所有文件和目录 要删除文件,您必须对文件及其存储文件夹具有写入权限。文件的所有者不需要rw权限即可对其进行rm
shell_exec("rm -rf /var/www/public_html/assets/*");
但是使用rm-rf
命令时要小心
对于Windows,您需要2个命令:
shell_exec("RD /S /Q C:\pathto\assets");
shell_exec("MD C:\pathto\assets");
如果您有Linux服务器,并且PHP有权运行shell命令,您可以尝试使用一行命令递归删除资产中的所有文件和目录 要删除文件,您必须对文件及其存储文件夹具有写入权限。文件的所有者不需要rw权限即可对其进行rm
shell_exec("rm -rf /var/www/public_html/assets/*");
但是使用rm-rf
命令时要小心
对于Windows,您需要2个命令:
shell_exec("RD /S /Q C:\pathto\assets");
shell_exec("MD C:\pathto\assets");
如果您有Linux服务器,并且PHP有权运行shell命令,您可以尝试使用一行命令递归删除资产中的所有文件和目录 要删除文件,您必须对文件及其存储文件夹具有写入权限。文件的所有者不需要rw权限即可对其进行rm
shell_exec("rm -rf /var/www/public_html/assets/*");
但是使用rm-rf
命令时要小心
对于Windows,您需要2个命令:
shell_exec("RD /S /Q C:\pathto\assets");
shell_exec("MD C:\pathto\assets");
如果您有Linux服务器,并且PHP有权运行shell命令,您可以尝试使用一行命令递归删除资产中的所有文件和目录 要删除文件,您必须对文件及其存储文件夹具有写入权限。文件的所有者不需要rw权限即可对其进行rm
shell_exec("rm -rf /var/www/public_html/assets/*");
但是使用rm-rf
命令时要小心
对于Windows,您需要2个命令:
shell_exec("RD /S /Q C:\pathto\assets");
shell_exec("MD C:\pathto\assets");
做一个