Php 我可以在桌面上上传图片和文件,但在手机上不行
我有一个单独的画廊和文件区。两者都可以在桌面上正常工作,但不能在移动设备上正常工作 画廊代码-每次只链接到无效的图像页面。即使在上传图像时也应该可以Php 我可以在桌面上上传图片和文件,但在手机上不行,php,html,mysql,Php,Html,Mysql,我有一个单独的画廊和文件区。两者都可以在桌面上正常工作,但不能在移动设备上正常工作 画廊代码-每次只链接到无效的图像页面。即使在上传图像时也应该可以 //When upload button is pressed if (isset($_FILES['image']['tmp_name'])) { $image = date(U).$_FILES['image']['name']; $target = "gallery_images/".$username."/".$im
//When upload button is pressed
if (isset($_FILES['image']['tmp_name'])) {
$image = date(U).$_FILES['image']['name'];
$target = "gallery_images/".$username."/".$image;
$sql = "INSERT INTO `images` (username, image) VALUES ('$username', '$image')";
move_uploaded_file($_FILES['image']['tmp_name'], $target);
mysqli_query($link, $sql);
//checking to see if uploaded file is actually an image
$file_type = image_type_to_mime_type(exif_imagetype($target));
$allowed = array("image/jpeg", "image/jpg", "image/gif", "image/png", "image/svg+xml", "image/bmp", "video/x-flv". "video/mp4", "application/x-mpegURL", "video/MP2T", "video/3gpp", "video/quicktime", "video/x-msvideo", "video/x-ms-wmv");
if(in_array($file_type, $allowed)){
header("location:gallery.php");
}else{
header("location:invalid_file.php?img=$image");
}
}
文件代码-将文件名上载到db,但实际上不会将文件放入指定的文件夹中
//When uploadfile is pressed - file is stored in db and folder
if (isset($_FILES['file']['tmp_name'])) {
if($_FILES['file']['name'] == $row["file"]){
header("location:file_copy.php");
}else{
$file = $_FILES['file']['name'];
$target = "file_storage/".$username."/".$file;
$sql = "INSERT INTO `files` (username, file) VALUES ('$username', '$file')";
move_uploaded_file($_FILES['file']['tmp_name'], $target);
mysqli_query($link, $sql);
header("location:files.php");
}
请将我的正确代码与您的代码进行比较
<?php
$connection=mysqli_connect("localhost","root","","imgup");
if(isset($_POST['create_post'])){
$post_image = $_FILES['image']['name'];
$post_image_temp = $_FILES['image']['tmp_name'];
move_uploaded_file($post_image_temp, "images/$post_image");
$query = "INSERT INTO img(post_image) ";
$query .= "VALUES('{$post_image}')";
$create_post_query = mysqli_query($connection, $query);
}
?>
<form action="fileup.php" method="post" enctype="multipart/form-data">
<label for="post_image">Post Image</label>
<input type="file" name="image">
<input type="submit" name="create_post" value="Publish">
</form>
日志中有错误吗?你的代码很奇怪。为什么保存文件后要检查文件类型?。您可以使用php的finfo函数来获取Mimetype@Akintunde它是这样写的,因为我是一个白痴谁匆忙!非常感谢你指出这一点,我现在就把它修好了。谢谢你的快速回复。我们将查看错误日志