English 中文(简体)
为什么要打上这支子宫顶罩的工作?
原标题:Why won t this php upload script work?

我有一份“html”表格,其中附有名为“形象”的文档,该图显示该法典的“网址”档案:

$date =  date( "Y_m_d_H_i_s_u" );

function upload() {

$info = pathinfo($_FILES[ image ][ name ]);
$target = "uploads/" . $date . $info[ extension ];

if(move_uploaded_file($_FILES[ image ][ tmp_name ], $target)) {
    return true;
} else{
    return false;
}
}

我希望档案名称有时间,而不是原始档案名称。 我可以指出,为什么这赢得了工作! 所有上载的档案都称为延期。 一些日子赢得工作。

最佳回答

Your scope is wrong for $date. You will want to either pass $date to your function or make it a global varible

$date =  date( "Y_m_d_H_i_s_u" );

function upload($date) {
    $info = pathinfo($_FILES[ image ][ name ]);
    $target = "uploads/" . $date . $info[ extension ];

    if(move_uploaded_file($_FILES[ image ][ tmp_name ], $target)) {
        return true;
    } else{
        return false;
    }
}

or

$date =  date( "Y_m_d_H_i_s_u" );

function upload() {
    global $date;
    $info = pathinfo($_FILES[ image ][ name ]);
    $target = "uploads/" . $date . $info[ extension ];

    if(move_uploaded_file($_FILES[ image ][ tmp_name ], $target)) {
        return true;
    } else{
        return false;
    }
}
问题回答

$date is outside of the scope of your function. There are 2 ways to fix this:

Option 1

$date = date( "Y_m_d_H_i_s_u" );

function upload() {
    globel $date;
    $info = pathinfo($_FILES[ image ][ name ]);
    $target = "uploads/" . $date . $info[ extension ];

    if(move_uploaded_file($_FILES[ image ][ tmp_name ], $target)) {
        return true;
    }
    else{
        return false;
    }
}

Option 2

$date = date( "Y_m_d_H_i_s_u" );

function upload($date) {
    $info = pathinfo($_FILES[ image ][ name ]);
    $target = "uploads/" . $date . $info[ extension ];

    if(move_uploaded_file($_FILES[ image ][ tmp_name ], $target)) {
        return true;
    }
    else{
        return false;
    }
}

upload ($date);

您也可考虑返回<代码>move_uploaded_file。 直接

return move_uploaded_file($_FILES[ image ][ tmp_name ], $target)

This is my observation , you are having scope issues

$date =  date( "Y_m_d_H_i_s_u" );

如果日期总是会发生变化

function upload() {
    $date =  date( "Y_m_d_H_i_s_u" );
    $info = pathinfo ( $_FILES [ image ] [ name ] );
    $target = "uploads/" . $date . $info [ extension ];
    if (move_uploaded_file ( $_FILES [ image ] [ tmp_name ], $target )) {
        return true;
    } else {
        return false;
    }
}




相关问题
Mysql compaire two dates from datetime?

I was try to measure what is faster and what should be the best way to compare two dates, from datetime record in MySql db. There are several approaches how to grab a date from date time, but I was ...

iPhone Date Picker rolls over to 2010 on December 27th?

So I implemented a UIDatepicker in one of my applications for scheduling and autodialing teleconferences... everything is pretty much ready to go except, while testing I noticed that when the date ...

Convert date Python

I have MMDDYY dates, i.e. today is 111609 How do I convert this to 11/16/2009, in Python?

specifying date format when using $form->inputs() in CakePHP

I am wondering if there is a way to specify the date format in the forms created using CakePHP s $form->inputs(); Please note that this is not the individual $form->input() but instead $form->inputs() ...

NSDateFormat, super simple! Where am I screwing up?

Ok, this is really simple, maybe I m a getting a bit burnt out, but seems like it should work, Query XML feed, put out date string, format, display in a cell. The issue is I m a getting a NULL ...

sqlite writing a date into an email

I am exporting a date value from sqlite and placing it into an email. The date appears like this 279498721.322872 I am using Objective C in an Iphone App. Does anyone know how to make this export ...

热门标签