gpt4 book ai didi

php - PHP中不存在的文件夹中的图像上传

转载 作者:行者123 更新时间:2023-11-29 11:21:48 24 4
gpt4 key购买 nike

我遇到了一个问题,我需要将图像上传到文件夹并将其路径存储到数据库中。

如果该文件夹不存在,则创建新文件夹,然后将其存储在那里并将完整路径保存到数据库中。

    $file_name=$_FILES["uploadedimage"]["name"];
$temp_name=$_FILES["uploadedimage"]["tmp_name"];
$imgtype=$_FILES["uploadedimage"]["type"];
$ext= GetImageExtension($imgtype);

要使用的图像名称

    $imagename=("Userimage")."-".time().$ext;

图像路径

$target_path = "images/".$imagename

条件

if(move_uploaded_file($temp_name, $target_path))
{
$query_upload="INSERT into images_tbl (images_path , submission_date) VALUES ('".$target_path."','".date("Y-m-d")."')";
$imagedb= mysqli_query($con,$query_upload);

while($imagepath = mysqli_fetch_array($imagedb))
{
echo "success";
}
}

最佳答案

很简单:

 $target_path = 'images/'.$imagename;
if(!is_dir($target_path)) mkdir($target_path, 0755);

当你可以使用' '时,不要使用“”,因为每次你使用“..”时,php都会尝试在内部查找变量,白白浪费时间。 ;)

关于php - PHP中不存在的文件夹中的图像上传,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38788275/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com