You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

从mysqli迁移至PDO后图片上传函数与变量配置问题咨询

迁移mysqli到PDO后图片上传功能失效问题

正在将使用多年的mysqli小型系统迁移至PDO,多数功能已迁移成功,但图片上传功能无法工作,其他如添加、编辑条目等功能均正常。目前遇到变量设置及函数调用的问题,转换后的应用似乎无法识别相关变量或函数,且无任何报错信息。原mysqli系统使用完全相同的代码可正常工作,路径等配置确认正确。

一、文件引入方式

原mysqli系统中,FAQ添加页面的文件引入代码如下:

include 'config/functions.php';
include 'config/config.php';

二、配置变量的疑问

1. 图片上传路径设置

原配置文件中的路径定义:

$faqpath='C:/xampp/htdocs/test/images/faqs/';

我尝试改为常量定义形式:

define('faqpath','C:/xampp/htdocs/test/images/faqs/');

请问这种修改方式是否正确?

2. 图片尺寸设置

原系统中的图片尺寸变量设置:

#FAQ Image Dimension Settings
$faq_thumb_width = 400;
$faq_thumb_height = 250;
$faq_large_width = 600;
$faq_large_height = 315;

使用PDO时是否需要改为以下常量定义形式?

#FAQ Image Dimension Settings
define('faq_thumb_width','400');
define('faq_thumb_height','250');
define('faq_large_width','600');
define('faq_large_height','315');

三、图片上传函数的疑问

原系统使用phpthumb实现的图片上传函数如下($pagelink为经过清洗的别名,用于生成图片文件名):

function thumb_upload_image($image,$width,$height,$upload_path) {

if($height > 0 and $width > 0) {

if(file_exists($upload_path)) { unlink($upload_path); }

require_once('config/thumb/phpthumb.class.php');
$phpThumb = new phpThumb();

$phpThumb->setSourceFilename($image);

$phpThumb->h = $height;
$phpThumb->w = $width;
$phpThumb->q = 95;
$phpThumb->zc = true;

$phpThumb->config_output_format = 'jpeg';
$phpThumb->config_error_die_on_error = false;
if(!$phpThumb->GenerateThumbnail()) {
echo 'Failed: '.implode("\n", $phpThumb->debugmessages);
}
if(!$phpThumb->RenderToFile($upload_path)) {
echo 'Failed: '.implode("\n", $phpThumb->debugmessages);
}
}
return 1;

}

function faq_upload_images($image,$type,$d,$f,$pagelink) {
$smallimage = $faqpath . $pagelink . "-thm-$d.jpg";
$bigimage = $faqpath . $pagelink . "-lrg-$d.jpg";
thumb_upload_image($image,$faq_thumb_width,$faq_thumb_height,$smallimage);
thumb_upload_image($image,$faq_large_width,$faq_large_height,$bigimage);
}

function delete_faq_image($pagelink,$d)
{
$smallimage = $faqpath . $pagelink . "-thm-$d.jpg";
$bigimage = $faqpath . $pagelink . "-lrg-$d.jpg";
if (file_exists($smallimage)) { unlink($smallimage); }
if (file_exists($bigimage)) { unlink($bigimage); }
}

这些函数是否需要调整格式?

内容的提问来源于stack exchange,提问作者Tilly

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.11 14:53:10