PHP上传文件获取url文件上传上去了可是url获取不到
if($do=="soft"){If_rabc($action,$do);//检测权限$salesid=$_SESSION[userid];$filename=md5(t...
if($do=="soft"){
If_rabc($action,$do); //检测权限
$salesid=$_SESSION[userid];
$filename= md5(time().rand(0,9).$_FILES["filedata"]["name"]).'.'.pathinfo($_FILES["filedata"]["name"],PATHINFO_EXTENSION);
$url= "uploadfile/".$filename;
move_uploaded_file($_FILES["filedata"]["tmp_name"],"uploadfile/".$filename);
if($_FILES["filedata"]["size"]>"12400"){
$resizeimage = new resizeimage("uploadfile/".$filename, "137", "123", "1","uploadfile/"."m_".$filename);
}else{
$resizeimage = new resizeimage("uploadfile/".$filename, "137", "123", "1","uploadfile/"."m_".$filename);
}
$file = "uploadfile/".$filename;
$newfile = "news/uploadfile/".$filename;
if (!copy($file, $newfile)) {
echo "failed to copy $file... ";
}
$created_at=date("Y-m-d h:i:s");
$sql = "INSERT INTO `photo` (`salesid`,`filename`,`intro`,`created_at` ) VALUES ( '$salesid','$filename','文档图片','$created_at');";
if($db->query($sql)){
$url= "uploadfile/".$filename;
exit("{'err':'','msg':{'url':'!".$url."'}}");
}else{
exit(error($msg));
}
}
我现在想把写入数据库的操作去掉,可是我直接去掉的话 就会文件上去了url获取不到 哪位大神帮我看一下 展开
If_rabc($action,$do); //检测权限
$salesid=$_SESSION[userid];
$filename= md5(time().rand(0,9).$_FILES["filedata"]["name"]).'.'.pathinfo($_FILES["filedata"]["name"],PATHINFO_EXTENSION);
$url= "uploadfile/".$filename;
move_uploaded_file($_FILES["filedata"]["tmp_name"],"uploadfile/".$filename);
if($_FILES["filedata"]["size"]>"12400"){
$resizeimage = new resizeimage("uploadfile/".$filename, "137", "123", "1","uploadfile/"."m_".$filename);
}else{
$resizeimage = new resizeimage("uploadfile/".$filename, "137", "123", "1","uploadfile/"."m_".$filename);
}
$file = "uploadfile/".$filename;
$newfile = "news/uploadfile/".$filename;
if (!copy($file, $newfile)) {
echo "failed to copy $file... ";
}
$created_at=date("Y-m-d h:i:s");
$sql = "INSERT INTO `photo` (`salesid`,`filename`,`intro`,`created_at` ) VALUES ( '$salesid','$filename','文档图片','$created_at');";
if($db->query($sql)){
$url= "uploadfile/".$filename;
exit("{'err':'','msg':{'url':'!".$url."'}}");
}else{
exit(error($msg));
}
}
我现在想把写入数据库的操作去掉,可是我直接去掉的话 就会文件上去了url获取不到 哪位大神帮我看一下 展开
2个回答
展开全部
你如果不记录到数据库,总得把文件路径记到哪里吧
否则,怎么会知道文件路径在哪里呢
还是说你只想返回文件路径展示一下就罢了
那就把这一行改一下
if($db->query($sql)){
改成if(1){
就行了,恒成立
否则,怎么会知道文件路径在哪里呢
还是说你只想返回文件路径展示一下就罢了
那就把这一行改一下
if($db->query($sql)){
改成if(1){
就行了,恒成立
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询