我正在尝试使用PHP将图像上传到文件中,我是langue的新手,所以非常感谢帮助。要上传的图像来自带有输入的页面,代码似乎没有执行!非常感谢,这是我的代码(第一个HTML,第二个PHP): 我正在尝试使用PHP将图像上传到文件中,我是langue的新手,所以非常感谢帮助。要上传的图像来自带有输入的页面,代码似乎没有执行!非常感谢,这是我的代码(第一个HTML,第二个PHP):
<?php
include_once 'Includes/dbh.inc.php';
session_start();
?>
<!DOCTYPE html>
<html>
<head>
<title><?php echo $_SESSION['user']; ?></title>
<link href="https://fonts.googleapis.com/css?family=Open+Sans+Condensed:300|Tajawal|Quicksand|Raleway:100" rel="stylesheet">
<link rel="stylesheet" tyle="text/css" href="main.css">
</head>
<body>
<!-- START Header -->
<section class="headuser">
<div class="pagetitle">
C A T C H Y .
</div>
<div class="username">
<a href="UserProfile.php"><?php echo $_SESSION['user']; ?></a>
</div>
</section>
<!-- END Header -->
<!-- START Bio -->
<section class="Bio">
<div class="friends">
<br>freinds<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</div>
<div class="editbio">
<?php echo $_SESSION['user']; ?>
<form action="Includes/upload.php" id="bioimage" method="POST" enctype="multipart/form-data">
<input type="file" name="profileup">
<button type="submit" id = "submit" name="upload">Use!</button>
</form>
<form action="Includes/Post.inc.php" id="bioform" method="POST">
<textarea name="Text1" id= "content" placeholder="Tell everyone who you are" cols="50" rows="10"></textarea>
<br>
<button type="submit" id="submit" name="submit">Post!</button>
</form>
</div>
</section>
<!-- END Bio -->
</body>
</html>
&#13;
if(isset($_POST['submit'])) {
$file = $_FILES['profileup'];
$fileName = $_FILES['profileup']['name'];
$fileTmpName = $_FILES['profileup']['tmp_name'];
$fileSize = $_FILES['profileup']['size'];
$fileError = $_FILES['profileup']['error'];
$fileType = $_FILES['profileup']['type'];
$fileExt = explode('.', $fileName);
$fileActualExt = strtolower(end($fileExt));
$allowed = array('jpg', 'jpeg', 'png');
if (in_array($fileActualExt, $allowed)){
if ($fileError === 0){
if ($fileSize < 1000000){
$filenamenew = uniqid('', true).".".$fileActualExt;
$filedest = 'profileimages/'.$filenamenew;
move_uploaded_file($fileTmpName, $filedest);
header("Location: ../UserProfile.php?suc");
}else{
echo "your file was to big";
}
}else{
echo "There was an error uploading your file";
}
}else{
echo "you cant upload files of this type";
}
}else{
header("Location: ../UserProfile.php?fail");
}
?>
答案 0 :(得分:1)
我认为你可以使用你的按钮名称&#34;上传&#34;。
if(isset($_POST['submit']))
当您提交图片时,它必须正常工作。
if(isset($_POST['upload']))
答案 1 :(得分:0)
上传页面中没有执行php脚本的问题就是这行
if(isset($_POST['submit'])
因为此检查输入提交是在您的html中设置的,您已将提交按钮命名为上传
解决方案更改名称ofhttml buttton提交或更改条件到此
if(isset($_POST['upload']))