|
Posted by R.A.M. on 01/08/08 15:09
Hello,
I need to implement file upload on .php page. To do so I have written in
Paper.php:
<form id="AddEdition" name="AddEdition" action="AddEdition.php"
method="POST" enctype="multipart/form-data" onsubmit="return
ValidateEdition();">
<input type="file" id="SelectEditionFile" name="SelectEditionFile"
onblur="PassFile();" />
<input type="hidden" value="" id="EditionFile" name="EditionFile" />
<input type="text" id="Year" name="Year" /></td>
<select id="Month" name="Month">
<option value="01">January</option>
<option value="02">February</option>
<option value="03">March</option>
...
<option value="12">December</option>
</select>
<input type="submit" value="Send file" /> <input type="reset"
value="Cancel" /></td>
</form>
<script type="text/javascript">
var today = new Date();
document.AddEdition.Year.value = today.getFullYear();
function PassFile()
{
document.getElementById('EditionFile').value =
document.getElementById('SelectEditionFile').value;
}
</script>
(onblur is used because of bug.)
The file AddEdition.php is:
<?php
session_start();
require 'Scripts.inc';
if ($_SERVER['REQUEST_METHOD'] == 'POST' &&
isset($_POST['EditionFile']) && isset($_POST['Year']) &&
isset($_POST['Month']))
{
if (is_uploaded_file($_FILES['SelectEditionFile']['tmp_name']))
{
$file = $_FILES['SelectEditionFile']['name'];
$ext = @substr($file,
@strrpos($file, '.') ? @strrpos($file, '.') + 1 : @strlen($file),
@strlen($file));
$paper = 'Paper/Blask_' . $_POST['Year'] . '-' . $_POST['Month'] . '.' .
$ext;
@unlink($paper);
if (!move_uploaded_file($_FILES['SelectEditionFile']['tmp_name'], $paper))
{
$_SESSION['Error'] = 'Failed to move the file.';
}
}
else
{
$_SESSION['Error'] = 'Failed to upload file.';
}
}
header("Location: Paper.php?topic=Editions");
?>
The problem is that is_uploaded_file(...) returns false (I have verified).
I don't understand why. Please help.
/RAM/
Navigation:
[Reply to this message]
|