添加确认页面以上载脚本

时间:2011-06-24 20:24:14

标签: php

有人可以告诉我如何在上传完成后在PHP脚本中添加确认页面而不是文本行吗?

这是我目前的代码:

<?php 
$target = "upload/"; 
$target = $target . basename( $_FILES['uploaded']['name']) ; 
$ok=1; 
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
} 
else {
echo "Sorry, there was a problem uploading your file.";
}
?> 

2 个答案:

答案 0 :(得分:0)

// upload.php的

<?php 
$target = "upload/"; 
$target = $target . basename( $_FILES['uploaded']['name']) ; 
$ok=1; 
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " is ready to be uploaded. <a href='confirm.php?confirm=1&filename=". basename( $_FILES['uploadedfile']['name']). "'>Confirm to add your file into our system</a> or <a href='confirm.php?confirm=0&filename=". basename( $_FILES['uploadedfile']['name']). "'>Reverse upload</a>";
} 
else {
echo "Sorry, there was a problem uploading your file.";
}
?> 

// confirm.php

<?php
if ($_GET['confirm'])
{
    echo "Your file (".$_GET['filename'].") has been uploaded";
    die();
}

echo "Your upload was reverted";
?>

答案 1 :(得分:0)

只需创建一个新的confirmation.php文件,然后在文件成功上传时重定向。

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target)) 
{
header("location: confirmation.php");
} 
else {
echo "Sorry, there was a problem uploading your file.";
}

希望它会对你有所帮助。

欢呼声.. !!