可能重复:
如何在PHP中检查上传文件的文件类型?
我在我的网站上传了功能,只允许pdf上传.如何检查上传的文件是否只是pdf.只是喜欢ckeck getimagesize()图像文件.有没有办法检查文件肯定是PDF格式.我的代码如下所示.
$whitelist = array(".pdf");
foreach ($whitelist as $item) {
if (preg_match("/$item\$/i", $_FILES['uploadfile']['name'])) {
}
else {
redirect_to("index.php");
}
}
$uploaddir='uploads/';
$uploadfile = mysql_prep($uploaddir . basename($_FILES['uploadfile']['name']));
if (move_uploaded_file($_FILES['uploadfile']['tmp_name'], $uploadfile)) {
echo "succussfully uploaded";
}
Run Code Online (Sandbox Code Playgroud)
在这redirect_to,mysql_prep并由我定义的功能.但是mime类型可以使用headers更改.所以有什么方法可以检查文件是orignal pdf吗?
我有两个字段,一个是emailid,另一个是我的表单中的密码.我想检测当用户重新输入电子邮件和密码时,他不应该复制上面的内容.他必须再次手动编写.就像谷歌表格一样
我想在div中添加一个div,里面有很多div.我的代码如下所示:
<div id="main">
<div class="random no"></div>
<div class="random no"></div>
<div class="random no"></div>
<div class="random no"></div>
<div class="mydiv"></div>
</div>
Run Code Online (Sandbox Code Playgroud)
我的jQuery代码是:
$("#main").append("<div class='random no'> </div>");
Run Code Online (Sandbox Code Playgroud)
但它追随div"main"的最后一个孩子.如何在之前插入div #mydiv?
function myFunc($x, $y) {
echo "x : {$x}";
echo "y : {$y}";
}
$params = array("y" => 1, "x" => 2);
Run Code Online (Sandbox Code Playgroud)
是否可以myFunc像使用call_user_func_array函数一样调用,但数组的键会自动在函数中设置正确的参数?是否有任何功能可以执行此操作或是否可以创建此功能?例如 :
call_func('myFunc', $params);
Run Code Online (Sandbox Code Playgroud)
结果就是这样
x : 2
y : 1
Run Code Online (Sandbox Code Playgroud)
谢谢.
我有Javascript编写的许多功能,如userName(),password()等,但在提交表单上,我有一个单一的功能return formValidator();.
我希望函数调用所有其他函数并检查它们是否返回false.如果它们都是真的,那么它应该返回true,否则它应该返回false.
function userName(){
var x=document.forms["signupform"]["firstname"].value;
if(x=="" ||x==null){
document.getElementById("firstname").style.border="1px solid #F50A0A";
document.getElementById("firstname").style.boxShadow="2px 2px 5px #F50A0A";
return false;
}else {return true;}
}
function password(){
var z=document.forms["signupform"]["password"].value;
if(z=="" ||z==null){
document.getElementById("password").style.border="1px solid #F50A0A";
document.getElementById("password").style.boxShadow="2px 2px 5px #F50A0A";
return false;
}else {return true;}
}
Run Code Online (Sandbox Code Playgroud) 我有一个评论表,其中存储了所有评论,我想显示最近20条评论
$query="SELECT * FROM comment WHERE answerid=$answerid ORDER BY time DESC LIMIT 20";
Run Code Online (Sandbox Code Playgroud)
它给了我近20,但是从上往下的,但我想他们下往上.Means最后的评论(按时间)应在最后我用显示
$result = mysql_query($query);
$newresult = array_reverse($result);
while( $row = mysql_fetch_array($newresult) ) {
//my code
echo $row['content'];
}
Run Code Online (Sandbox Code Playgroud)
但这不起作用?
我想通过php条件销毁cookie但是在谷歌和php手册的大量研究之后我没有做任何事情.我在某个地方读过setcookie('cookie_name');但它只是擦除了cookie所以我的问题是如何通过php销毁cookie?