我正在编写一个脚本来将图像上传到我的应用程序.以下安全步骤是否足以使应用程序从脚本端安全?
这是我的脚本:
$filename=$_FILES['my_files']['name'];
$filetype=$_FILES['my_files']['type'];
$filename = strtolower($filename);
$filetype = strtolower($filetype);
//check if contain php and kill it
$pos = strpos($filename,'php');
if(!($pos === false)) {
die('error');
}
//get the file ext
$file_ext = strrchr($filename, '.');
//check if its allowed or not
$whitelist = array(".jpg",".jpeg",".gif",".png");
if (!(in_array($file_ext, $whitelist))) {
die('not allowed extension,please upload images only');
}
//check upload type
$pos = strpos($filetype,'image');
if($pos === false) {
die('error 1');
}
$imageinfo = getimagesize($_FILES['my_files']['tmp_name']);
if($imageinfo['mime'] != 'image/gif' …
Run Code Online (Sandbox Code Playgroud) 我们正在尝试将新的React Native应用程序集成到现有的原生Android应用程序中.遵循RN官方文档,我们设法使其工作,但有一些关于导航的问题.
我们有原生和非原生(JS)屏幕,我们需要一种在所有屏幕之间导航的好方法,无论屏幕是否为原生屏幕.
我们尝试采用本机导航和react-native-navigation来查看是否有任何地址我们的问题,但没有一个实际工作.
目前,我们已经注册了所有我们的RN屏幕,如下所示:
const provide = (store, Screen) => {
return props => (
<Provider store={store}>
<Screen {...props} />
</Provider>
);
};
const store = configureStore();
AppRegistry.registerComponent('Home', () => provide(store, HomeComponent));
Run Code Online (Sandbox Code Playgroud)
我们还创建了一个名为"Navigator"的本机模块,该模块具有称为openComponent
接受屏幕名称及其道具的导航方法.以下是openComponent
外观的实现方式:
// our native module code ...
@ReactMethod
public void openComponent(String name, String extra) {
try {
Intent intent = new Intent(this.getReactApplicationContext(), MyReactActivity.class);
intent.putExtra("moduleName", name);
intent.putExtra("extra", extra);
getCurrentActivity().startActivityForResult(intent, 0);
}
catch (Exception e) {
e.printStackTrace();
Crashlytics.logException(e.getCause());
} …
Run Code Online (Sandbox Code Playgroud) javascript android react-native react-native-android react-native-navigation
我写了一个bash脚本,当它挂起并向管理员发送电子邮件时重启Apache.代码如下所示.如果Apache进程的数量为零,代码将重新启动Apache.问题是:Apache有时挂起,进程仍然不为零,所以在这种情况下脚本不会重启Apache.需要的是:如果挂起并且进程不为零,我如何修改代码以重启Apache.
#!/bin/bash
if [ `pgrep apache2 -c` -le "0" ]; then
/etc/init.d/apache2 stop
pkill -u www-data
/etc/init.d/apache2 start
echo "restarting....."
SUBJECT="Apache auto restart"
# Email To ?
EMAIL="me@mydomain.com"
# Email text/message
EMAILMESSAGE="apache auto restart done"
# send an email using /bin/mail
/bin/mail -s "$SUBJECT" "$EMAIL" "$EMAILMESSAGE"
fi
Run Code Online (Sandbox Code Playgroud) 我正在运行一个使用类似于下表的表的应用程序.有一个文章表,还有另一个标签表.我想通过文章ID获取最新的30篇文章作为特定的标签订单.例如"acer",下面的查询将完成这项工作,但它没有正确编制索引,因为如果有很多与特定标签相关的文章,它会扫描很多行.如何运行查询以获得相同的结果而不扫描大量的行?
EXPLAIN SELECT title
FROM tag, article
WHERE tag = 'acer'
AND tag.article_id = article.id
ORDER BY tag.article_id DESC
LIMIT 0 , 30
Run Code Online (Sandbox Code Playgroud)
产量
id select_type table type possible_keys key key_len ref rows Extra
1 SIMPLE tag ref tag tag 92 const 220439 Using where; Using index
1 SIMPLE article eq_ref PRIMARY PRIMARY 4 testdb.tag.article_id 1
Run Code Online (Sandbox Code Playgroud)
以下是表格和样本数据:
CREATE TABLE `article` (
`id` int(11) NOT NULL auto_increment,
`title` varchar(60) NOT NULL,
`time_stamp` int(11) NOT NULL,
PRIMARY KEY (`id`)
) ENGINE=MyISAM DEFAULT …
Run Code Online (Sandbox Code Playgroud) 如何在 PHP 上使用 64 位整数的二进制字符串进行 Base64 编码?
此代码未按预期工作
<?PHP
$t=11545152599186258990;
$byte_array_t = pack('P',$t);
echo base64_encode($byte_array_t); //not correct result - it should be: LrwswB6fOKA=
echo '
';
$t=11;
$byte_array_t = pack('P',$t);
echo base64_encode($byte_array_t); //correct
Run Code Online (Sandbox Code Playgroud)
我这样做是因为我试图在 PHP 中实现以下代码(golang):
package main
import (
"fmt"
"encoding/base64"
"encoding/binary"
)
func main() {
dst := make([]byte, 8)
binary.LittleEndian.PutUint64(dst, uint64(11545152599186258990))
value :=base64.URLEncoding.EncodeToString(dst)
fmt.Println(value)
}
Run Code Online (Sandbox Code Playgroud) 我需要您的帮助来优化查询以避免使用 "使用filesort".查询的工作是选择属于特定标记的所有文章.查询是:
select title
from tag,
article
where tag = 'Riyad'
AND tag.article_id = article.id
order by tag.article_id
Run Code Online (Sandbox Code Playgroud)
表结构如下:
标签表
CREATE TABLE `tag` (
`tag` VARCHAR( 30 ) NOT NULL ,
`article_id` INT NOT NULL ,
KEY `tag` (`tag`),
KEY `article_id` (`article_id`)
) ENGINE = MYISAM ;
Run Code Online (Sandbox Code Playgroud)
条款表
CREATE TABLE `article` (
`id` INT NOT NULL AUTO_INCREMENT PRIMARY KEY ,
`title` VARCHAR( 60 ) NOT NULL
) ENGINE = MYISAM
Run Code Online (Sandbox Code Playgroud)
样本数据
INSERT INTO `article` VALUES (1, 'About Riyad');
INSERT …
Run Code Online (Sandbox Code Playgroud) 我正在尝试在HTML页面中编写ADD&DELETE按钮来删除或添加页面中的图像代码.DELETE按钮将删除按钮前的第一个图像.ADD按钮将新图像插入HTML页面,删除按钮将插入图像.
代码工作正常:单击DELETE按钮时删除图像,单击ADD按钮时插入图像.问题是:单击ADD按钮后插入的删除按钮不起作用.因此,如果单击"添加"按钮,然后单击"删除"按钮,图像将不会隐藏; click事件未触发.
这是代码:
<html>
<head>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.4.2.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('.img-post input').after('<button type="button" >Delete</button>');
$(".img-post button").click(function() {
$(this).prev().prev().remove();
$(this).prev().remove();
$(this).remove();
});
$(".add-img button").click(function() {
$('<img src="image3.jpg" /><input type="hidden" name="allimages[]" value="image3.jpg" /><button type="button" >Delete</button><br />').appendTo('.img-post');
});
});
</script>
</head>
<body>
<div class="img-post">
<img src="image1.jpg" /><input type="hidden" name="allimages[]" value="image1.jpg" /><br />
<img src="image2.jpg" /><input type="hidden" name="allimages[]" value="image2.jpg" /><br />
</div>
<div class="add-img">
<button type="button" >Add image</button>
</div>
</body>
</html>
Run Code Online (Sandbox Code Playgroud) mysql ×2
php ×2
android ×1
apache ×1
base64 ×1
bash ×1
encoding ×1
filesort ×1
go ×1
javascript ×1
jquery ×1
optimization ×1
performance ×1
react-native ×1
security ×1
upload ×1