Php 对非对象调用成员函数storeUploadedImage()
正如标题所示,出现了一个致命的php错误。完全错误是 注意:未定义变量:第95行“位置”中的项目 致命错误:对第95行“location”中的非对象调用成员函数storeUploadedImage() 抛出is error的函数如下所示Php 对非对象调用成员函数storeUploadedImage(),php,Php,正如标题所示,出现了一个致命的php错误。完全错误是 注意:未定义变量:第95行“位置”中的项目 致命错误:对第95行“location”中的非对象调用成员函数storeUploadedImage() 抛出is error的函数如下所示 public function storeUploadedImage( $image ) { if ( $image['error'] == UPLOAD_ERR_OK ) { // Does the Article object have a
public function storeUploadedImage( $image ) {
if ( $image['error'] == UPLOAD_ERR_OK )
{
// Does the Article object have an ID?
// Line 95 -----v
if ( is_null( $this->id ) ) trigger_error( "Article::storeUploadedImage(): Attempt to upload an image for an Article object that does not have its ID property set.", E_USER_ERROR );
// Delete any previous image(s) for this article
$this->deleteImages();
// Get and store the image filename extension
$this->imageExtension = strtolower( strrchr( $image['name'], '.' ) );
// Store the image
$tempFilename = trim( $image['tmp_name'] );
if ( is_uploaded_file ( $tempFilename ) ) {
if ( !( move_uploaded_file( $tempFilename, $this->getImagePath() ) ) ) trigger_error( "Article::storeUploadedImage(): Couldn't move uploaded file.", E_USER_ERROR );
if ( !( chmod( $this->getImagePath(), 0666 ) ) ) trigger_error( "Article::storeUploadedImage(): Couldn't set permissions on uploaded file.", E_USER_ERROR );
}
我在谷歌上搜索,寻找解决我的错误的方法,尽管看起来与我的问题无关
文章的其余部分是创建的,而不是图像。当我回来更新图片上传时,没有问题,没有错误,这让我感到困惑
id的类构造部分是
public function __construct( $data=array() ) {
if ( isset( $data['id'] ) ) $this->id = (int) $data['id'];
我还使用它在类的开头定义id
public $id = null;
我只能假设Id没有正确地传递给$this->Id
,并且保持为空,但我不知道如何修复此问题。虽然我可能也错了
这里调用该方法
if ( isset( $_POST['saveChanges'] ) ) {
// User has posted the articles edit form: save the new articles
$articles = new Article;
$articles->storeFormValues( $_POST );
$articles->insert();
if ( isset( $_FILES['image'] ) ) $article->storeUploadedImage( $_FILES['image'] );
header( "Location: admin.php?status=changesSaved" );
} elseif ( isset( $_POST['cancel'] ) ) {
您的对象称为
$articles
而不是$article
,更改为:
if ( isset( $_FILES['image'] ) ) $articles->storeUploadedImage( $_FILES['image'] );
// ^ note: s
您对
storeUploadedImage()的实际调用在哪里?您已经显示了方法本身,但没有显示调用-这就是问题所在。好的观点。我刚刚添加了名为dif的方法(isset($\u FILES['image'))$article s->storeUploadedImage($\u FILES['image');这肯定是问题所在,我怀疑你没有正确上传/覆盖文件。是的,你是对的。当我测试并再次运行该文件时,该文件没有正确上传。再试一次,它修复了它“facepalm”它总是这么简单。谢谢你的支持help@user1711576没问题:)