gpt4 book ai didi

php - 在mysql中存储图像路径以备后用

转载 作者:搜寻专家 更新时间:2023-11-01 08:47:38 26 4
gpt4 key购买 nike

我有一个向我的 Web 服务器发送图像的 Android 应用程序,图像已成功保存在目录中但不是路径(路径应保存在 mysql 中)。有没有办法做到这一点,以便我可以在需要时使用路径来恢复图像?

这是我的尝试:)

$target_path  = "./images";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);


$pic=($_FILES['photo']['name']);

$file_path=$_FILES['tmp_name'];

// include db connect class
define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__.'/android_connect/db_connect.php');

// connecting to db
$db = new DB_CONNECT();

$result = mysql_query("INSERT INTO scb(photo, name) VALUES('$pic', '$file_path')");//

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
}
else
{
echo "There was an error uploading the file, please try again!";
}

?>;

最佳答案

如果将临时路径保存到您的数据库,请保存您的最终上传目的地:

$target_path    =   "./images".basename( $_FILES['uploadedfile']['name']);
$pic = ($_FILES['photo']['name']);
$file_path = $_FILES['tmp_name'];

// include db connect class
define('__ROOT__', dirname(dirname(__FILE__)));
require_once(__ROOT__.'/android_connect/db_connect.php');

// connecting to db
$db = new DB_CONNECT();

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name'])." has been uploaded";
// Make your database insert only if successful and insert $target_path, not $file_path
// Use mysqli_ or PDO with prepared statements
$result = mysql_query("INSERT INTO scb(photo, name) VALUES('$pic', '$target_path')");//
}
else
echo "There was an error uploading the file, please try again!";

关于php - 在mysql中存储图像路径以备后用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26696001/

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