Posts: 26
Name: Prithwiraj Bose
Location: Kalyani, West Bengal, India
|
PHP header redirection will not work here. Because, the script has already started output, before the scope of header function arrives.
The updated code is given below.
Code:
<form name="upload" enctype="multipart/form-data" method="post" action="">
<span class="style1">JMI REPORTS, INC. - ONLINE INSPECTOR APPLICATION </span>
<p><span class="as">We are always seeking qualified individuals who are interested in conducting field inspections with JMI Reports. </span></p>
<p class="as">Currently, we have our greatest need in <a href="needsinspector.php" target="_blank">these areas. (click here)</a></p>
<p class="as">Although we may not have an immediate need in the area you live, you are welcome to submit an application for future consideration.</p>
<p class="as"><strong>THIS PROCESS WILL TAKE ABOUT 15 MINUTES AND INCLUDES A SHORT KNOWLEDGE ASSESSMENT.</strong></p>
<p>Request a username:
<input type="text" name="username" />
<span class="gg">(please write this down) </span></p>
<p>Request a password:
<label>
<input type="text" name="password" id="password" />
</label>
<span class="gg">(please write this down) </span></p>
<p>
Badge Photo Upload:
<input type="file" name="file" />
</p>
<p class="gg"><strong>If you do not have a photo immediately available, put in your requested username and password and hit upload</strong>. </p>
<p class="gg"><strong>Then click CONTINUE below to login and completed the registration process.</strong></p>
<p>
<input type="submit" name="submit" value="Upload" />
<span class="as"><strong><a href="initlogin.php">CONTINUE</a></strong></span></p>
<p>
<?php
if(isset($_POST['submit'])) {
$dir = "/home/content/n/w/c/nwclark/html/jmi2/secure/idphotos/"; //Upload directory
$error = ""; //Setting a false error
$address = "http://97.74.52.5/jmi2/".$_SERVER['HTTP_HOST']."/"; //Getting the web address
$randomNumber= time();
$username=$_POST['username'];
$password=$_POST['password'];
$file_name = $randomNumber.$username.$_FILES['file']['name']; //Getting the file name
$file_type = $_FILES['file']['type']; //Getting the file type
$file_size = "".$_FILES['file']['size']." bytes"; //Getting the file size
$file_tmp = $_FILES['file']['tmp_name']; //Setting the temporary name
$file_address = $address.$dir.$file_name; //URL of file
?>
<?
mysql_query("INSERT INTO jmi10.user (username,photo,password) VALUES ('$username', '$file_name', '$password')") or die("Error: " . mysql_error());
if(file_exists($dir.$file_name)) {
$error = "<br />Error: A file with the same name already exists!";
}
else {
@copy ($file_tmp, $dir.$file_name) or ($error="<br />Error: File could not
be copied!");
}
if($error != "") {
echo $error;
}
else {
echo "<br />File successfully uploaded!\n";
echo "<br />Name: ".$file_name."\n";
echo "<br />Size: ".$file_size."\n";
echo "<br />Type: ".$file_type."\n";
echo "<br />You're being redirected...";
?>
<script type='text/javascript'>
document.location="redirect_url_here";
</script>
<?php
}
}
?>
</p>
<p class="as"> </p>
The red colored codes are changed (from the original) and the redirecting javascript code is added. The Grey code can be removed, if you don't want to show any upload successful notification.
|