我有index.php和upload.php。index.php提供选择图像的选项,一旦单击上传图像按钮,upload.php就会调用它,然后创建一个目录并保存图像。
索引.php
<!DOCTYPE html>
<html>
<head>
<title>Face Recognition</title>
<link href="main.css" rel="stylesheet" type="text/css" href="" />
</head>
<body>
<form enctype="multipart/form-data" action="upload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="512000" />
Select file: <input name="userfile" type="file" />
<?php $file = isset($filename) ? $filename : ''; ?>
<input type="text" name="filename" value="<?php echo $file; ?>" />
<input type="submit" value="Upload Images" />
</form>
</body>
</html>
上传.php
<?php
$uploaddir = 'G:/dataset/' . $_POST['filename'] . "/";
// check if directory exists
if(!is_dir($uploaddir)){
mkdir($uploaddir);
}
$uploadfile = $uploaddir . basename($_FILES['userfile']['name']) ;
echo $uploadfile;
move_uploaded_file($_FILES['userfile']['tmp_name'],$uploadfile);
?>
当upload.php被调用时,页面重定向到upload.php页面并显示上传文件路径。我不想重定向到upload.php。我想将所有内容都保存在单个 index.php 文件中。这样上传图片后,它会在同一个index.php 上显示上传文件的路径。我们怎样才能实现它。?
富国沪深
一只斗牛犬