我有一些上傳表單,file_exists在同一個請求的兩個地方爲同樣的條件返回不同的結果。以下是示例代碼。file_exists在兩個地方爲相同的條件返回不同的結果
$flag = file_exists($_FILES['image']['name']); // return TRUE
move_uploaded_file(
$_FILES['image']['tmp_name'],
'uploads/' . $_FILES['image']['name']
);
require_once APPPATH . 'custom_classes/ImageResize.class.php';
$img_resize = new ImageResize($_FILES['image']['tmp_name']); // here is the Exception thrown
$img_resize->set_resize_dimensions(650, 451);
$img_resize->crop_image();
$img_resize->save_image('uploads/cropped.jpg');
$img_resize->free_resourses();
這裏是拋出異常的類構造函數。
public function __construct($filepath)
{
if (!file_exists($filepath)) // same condition as above, throws Exception
{
throw new Exception('File not found!');
}
$this->get_source_dimensions($filepath);
$this->load_source_img($filepath);
}
這讓我瘋狂。我可以從文件系統傳遞臨時路徑,但我非常確定此代碼之前工作過,現在它給了我這個。難道我做錯了什麼?
那麼,如果你移動它,它將不再存在於舊的位置...... – jeroen