Hi,
We are using Apache 2.52 with PHP5. The upload file script which worked under PHP4 is not working under PHP5. Here is php scripts to upload file
<?php
include("../ssi/header.html");
?>
<p class="main">
<center><h2 class="main">Upload Page</h2>
<br>
<P>
<form enctype="multipart/form-data" action="results.html" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="500000000">
Upload File: <input name="uploadfile" type="file" size=40>
<P>
File Date:
<select name="quarter">
<option value="" selected>Quarter</option>
<? for ($i=1; $i<=4; $i++) { echo "<option value=\"$i\">$i</option>\n"; } ?>
</select>
<select name="year">
<option value="" selected>Year</option>
<?php $Y = date("Y"); $Y1 = $Y+1; $Y0 = $Y-1;
echo "<option value=\"$Y0\">$Y0</option>\n";
echo "<option value=\"$Y\">$Y</option>\n";
echo "<option value=\"$Y1\">$Y1</option>\n";
?>
</select>
</P>
<P>
<input type="submit" value="Upload File">
</form>
</P>
</center>
<br>
<?
include("../ssi/footer.html");
?>
results.php
<?PHP
$quarter = $_POST['quarter'];
$year = $_POST['year'];
$uploaddir = $_SERVER['DOCUMENT_ROOT'].'/test/';
//$uploaddir = '/tmp/';
echo (file_exists($uploaddir) && is_dir($uploaddir)) ? 'Directory path ok' : 'Directory does not exist';
if (is_uploaded_file($_FILES['uploadfile']['tmp_name'])) {
$name = $_FILES['uploadfile']['name'];
$uploaddir = $uploaddir . $name;
$tempname = $_FILES['uploadfile']['tmp_name'];
$result = move_uploaded_file($_FILES['uploadfile']['tmp_name'],$uploaddir);
if ($result == 1){ echo "<p>File uploaded.</p>";}
else { die("Error uploading file. Please contact an administrator");
}
}
?>
I tried $uploaddir to /tmp and it works fine.
if $uploaddir is set to /opt/www/domain.com/html/test/ it gives following error
[Thu Jul 20 15:17:14 2006] [error] [client 172.16.22.66] PHP Warning: move_uploaded_file(/opt/www/domain.com/html/test/test.txt) [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: failed to open stream: Permission denied in /opt/www/domain.com/html/upload/results.html on line 20, referer: http://192.168.19.66/upload/
[Thu Jul 20 15:17:14 2006] [error] [client 172.16.22.66] PHP Warning: move_uploaded_file() [<a href='function.move-uploaded-file'>function.move-uploaded-file</a>]: Unable to move '/tmp/phpOTS20J' to '/opt/www/domain.com/html/test/test.txt' in /opt/www/domain.com/html/upload/results.html on line 20, referer: http://192.168.19.66/upload/
Directory persmission is set 777 to all the directory from /opt/www/domain.com/html/test. I was able to copy file to $uploaddir from command prompt as user apache.
Please help.
thanks.