Duplicate question: Can't upload files to folder using form
P粉764785924
P粉764785924 2023-08-08 21:57:36
0
1
528
<p>admin.php:</p> <pre class="brush:php;toolbar:false;"><!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Admin</title> </head> <body> <form action="upload.php" method="POST" enctype="multipart/form-data"> Image: <input type="file" name="image"> <br> Sale or Rent: <input type="text" name="isForSale"> <br> Price: <input type="text" name="price"> <br> Location: <input type="text" name="location"> <br> Area: <input type="text" name="area"> <br> Bedrooms: <input type="text" name="bedrooms"> <br> <button type="submit">Upload</button> </form> </body> </html></pre> <p>upload.php:</p> <pre class="brush:php;toolbar:false;"><?php if(isset($_POST['submit'])) { $file = $_FILES['image']; $fileName = $_FILES['image']['name']; $fileTmpName = $_FILES['image']['tmp_name']; $fileSize = $_FILES['image']['size']; $fileError = $_FILES['image']['error']; $fileType = $_FILES['image']['type']; $fileExt = explode('.',$fileName); $fileActExt = strtolower(end($fileExt)); $allow = array('jpg','jpeg','png'); if(in_array($fileActExt,$allow)) { if($fileError === 0) { $fileNewName = uniqid('', true).".".$fileActExt; $fileDestination = 'FamilyRealEstate/FamilyRealEstateImages/uploads'.$fileNewName; move_uploaded_file($fileTmpName, $fileDestination); header("Location: admin.php?uploadsuccess"); } else { echo "Error uploading your file"; } } else { echo "You cannot upload files of this type.(Only jpg, jpeg, png)"; } } ?></pre> <p>我正在尝试将图片上传到网络并在文件夹中保存它。这似乎不起作用。它只是去到空白页面(upload.php)。可能是因为文件夹的权限,然而我正在使用Ubuntu,并且非常新,所以我真的不知道如何修复它。</p>
P粉764785924
P粉764785924

reply all(1)
P粉530519234

Your submit button should contain the name attribute with the submit value:

<button type="submit" name="submit">Upload</button>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template