Php 如何在服务器文件夹中保存图像
这是我上传图片的php代码。带有一些文本。这个脚本在android应用程序代码中使用。 图像id、图像url和文本正确保存在数据库中,但图像未保存在服务器文件夹中。为什么会发生这种情况Php 如何在服务器文件夹中保存图像,php,android,image,server,Php,Android,Image,Server,这是我上传图片的php代码。带有一些文本。这个脚本在android应用程序代码中使用。 图像id、图像url和文本正确保存在数据库中,但图像未保存在服务器文件夹中。为什么会发生这种情况 <?php if($_SERVER['REQUEST_METHOD']=='POST'){ $image = $_FILES['image']; $fullname = $_POST['fullname']; require_once('dbCo
<?php
if($_SERVER['REQUEST_METHOD']=='POST'){
$image = $_FILES['image'];
$fullname = $_POST['fullname'];
require_once('dbConnect.php');
$sql ="SELECT id FROM uploadfinding ORDER BY id ASC";
$res = mysqli_query($conn,$sql);
$id = 0;
while($row = mysqli_fetch_array($res)){
$id = $row['id'];
}
$path = "uploads/$id.png";
$actualpath = "My_url/$path";
// query for db
$sql = "INSERT INTO uploadfinding (image,fullname) VALUES ('$actualpath','$fullname')";
if(mysqli_query($conn,$sql)){
file_put_contents($actualpath,base64_decode($image));
echo "Successfully Uploaded";
}
mysqli_close($conn);
}else{
echo "Error";
}
?>
确保添加了'enctype'=>“多部分/表单数据”,例如:
<form method="post" name="abc" enctype="multipart/form-data">
这是这个问题的工作代码
<?php
header("content-type:application/json");
require_once('dbConnect.php');
if($_SERVER['REQUEST_METHOD']=='POST'){
if(isset($_FILES['image'])){
$errors= array();
$fullname = $_POST['fullname'];
$location = $_POST['location'];
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$date=date('Y-m-dH:i:s');
$path="folder_name/".$date.$file_name;
$actualpath = "http:myUrl/uploadfinding/$path";
if(empty($errors)==true){
move_uploaded_file($file_tmp,$path);
$sql = "INSERT INTO uploadfinding (image,fullname,location,) VALUES ('$actualpath','$fullname','$location',)";
if(mysqli_query($conn,$sql)){
echo "message";
}
}else{
print_r($errors);
}
}
}
?>
要上传文件,您必须使用move\u uploaded\u file()函数。我已经使用了这个函数,但是没有发生任何事情。首先检查文件上传是否有错误,特别是$\u FILES['image']['error']
@AdityaBhatt html在哪里???这个脚本有太多问题,需要一个培训课程来解决所有问题。所以不是教程站点文件内容($actualpath,base64_decode($image));您是否检查了文件夹的权限?