Home > PHP > File uploading using php when safe mode is ON

File uploading using php when safe mode is ON

October 8th, 2009

have writin a basic php script to upload files onto my web server but I am getting this error:

Warning: SAFE MODE Restriction in effect. The script whose uid is 519 is not allowed to access /var/www owned by uid 0 in /home/virtual/site8/fst/va

r/www/html/Admins/Admins/upload.php on line 14
Error: could not make directory.

Here is my code:

<?
session_start();

if (!session_is_registered(”SESSION”))
{
header(”Location: http://www.mywebsite.com/Admins/index.php“);
}
$dirname = “files”;
define(PATH, “/var/www/”);
$filename = $myfile_name;
if ($filename != “”)
{
if (!$dir = @opendir(PATH.$dirname))
mkdir(PATH.$dirname, 0700) or die(”<b>Error:</b> could not make directory.”);
copy($myfile, PATH.$dirname.”/”.$filename) or die(”<b>Error:</b> could not copy file.”);
unlink($myfile) or die(”<b>Error:</b> could not delete uploaded file.”);
echo “Upload sucessful.”;
}
else
{
echo “You must select a file to upload.”;
}
?>
<title>MyWebSite Administration</title>
<div align=”center”><B><font size=”+5″>MyWebSite File Upload</font></B>
</div>
<form action=”upload.php” enctype=”multipart/form-data” method=”POST”>
<div align=”center”>    <br />
<table width=”335″ border=”1″>
<tr>
<td width=”97″>File Directory:</td>
<td width=”222″><input name=”myfile” type=”file” id=”myfile”></td>
</tr>
<tr>
<td colspan=”2″><div align=”center”>
<input type=”submit” name=”submit2″ value=”Submit”>
</div></td>
</tr>
</table>
<input type=”hidden” name=”submit” value=”Submit”>
</div>
</form>
<p align=”center”><a href=”http://www.mywebsite.com/Admins/Admins/main.php“>Return to Admin Menu</a> | <a href=”http://www.mywebsite.com/Admins/main.php“>Return to Main Menu</a> </p>

There some more things I need added to the script.
1) Choose the directory to upload the file, but has the default path of http://www.mywebsite.com/files/
2) Have the php script print out all the files in that directory and have the option to delete and rename
3) When a file has sucessfuly uploaded, “Upload Complete” prints out under my title in red font.

I’m happy to give an A grade to anyone who can help me with my code.

PHP

  1. No comments yet.
  1. No trackbacks yet.
You must be logged in to post a comment.