创建上传图像代码的文件时,不将图像上传到文件夹 [英] When creating file which uploads images code not uploading image to folder
问题描述
大家好,今天我正在观看有关如何使用php上传图像的教程,并在我偶然发现问题时进行处理。我的代码正常工作,显示了成功标题,但实际文件没有上传到所需的文件夹。我多次检查了文件夹的拼写和目的地,并将文件的目的地切换到我的rootfolder,仍然没有图像上传。我还没有将数据插入数据库。下面是我的PHP代码,这里是youtube教程的链接
mmtuts文件上传教程
Hello everyone, today I was watching a tutorial on how to upload images using php and working on it when I stumbled upon an issue. My code was working, the success header was shown, however the actual file was not uploading to the desired folder. I checked the spelling and destination of the folder multiple times and have switched the destination of the file to my rootfolder and still no image was upoaded. I am not at the point of inserting my data into the database yet. Below is my php code and here is the link of the youtube tutorial
mmtuts File upload tutorial
<?php
if(isset($_POST['submit'])){ //check if submit button with name submit pressed//
$file = $_FILES['file']; //save file uploaded from [input type= file] with name file//
$fileName = $_FILES['file']['name']; //getting file uploaded name from inline array//
$fileTmpName = $_FILES['file']['tmp_name']; //getting file temporary name from inline area recieved form print_r() f//
$fileSize = $_FILES['file']['size']; //getting file size form inline area recieved from print_r() f//
$fileError = $_FILES['file']['error']; //getting file upload error from inline array//
$fileType = $_FILES['file']['type']; //getting uploaded file type//
$title = $_POST['title']; //getting title for photo from index.php title input//
$desc = $_POST['desc']; //getting image description from index.php desc input//
$fileExt = explode('.', $fileName); //removeing all '.' from fileName//
$fileActExt = strtolower(end($fileExt)); //putting the type of file in lower case by only using the end letters of file and functioning to strtolower//
$allowed = array('jpg', 'jpeg', 'png'); //in array setting types of allowed files//
if(in_array($fileActExt , $allowed)){
if($fileError === 0){
if($fileSize < 20000000){
$fileNameNew = uniqid('', true). '.' .$fileActExt;
$fileDest = 'rootfolder/' . $fileNameNew;
move_uploaded_file($fileTmpName, $fileDest);
header("Location: index.php?upload=success");
}else{
echo "File to large";
}
}else{
echo "error!";
}
}else{
echo "Unaccepted file type";
}
}
我是什么尝试过:
我试过切换目的地,检查并仔细检查目的地。我甚至尝试将文件放入我的根文件夹。
What I have tried:
I have tried switching the destination, checking and double checking the destination. I have even tried putting the file into my root folder.
推荐答案
_POST [' submit'])){ // 检查提交按钮是否按下提交名称//
_POST['submit'])){ //check if submit button with name submit pressed//
file =
file =
_FILES [ ' file']; // 使用名称文件保存从[input type = file]上传的文件//
_FILES['file']; //save file uploaded from [input type= file] with name file//
这篇关于创建上传图像代码的文件时,不将图像上传到文件夹的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!