Hello everyone,
I've been trying to play around with uploading files into my server directory. I'm trying to upload images to my public_html/images folder
I've played around with some code and was able to get the image to upload, but it went into my public_html directory instead of the public_html/images one.
Here is the code:
$uploaddir = '/public_html/Images/';
if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];
$filePath = $uploadDir . $fileName;
$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}
if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
}
$query = "INSERT INTO upload2 (name, size, type, path ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";
mysql_query($query) or die('Error, query failed : ' . mysql_error());
echo "<br>File uploaded<br>";
}
?>
<form action="" method="post" enctype="multipart/form-data" name="uploadform">
<table width="350" border="0" cellpadding="1" cellspacing="1" class="box">
<tr>
<td width="246"><input type="hidden" name="MAX_FILE_SIZE" value="2000000"><input name="userfile" type="file" class="box" id="userfile">
</td>
<td width="80"><input name="upload" type="submit" class="box" id="upload" value=" Upload "></td>
</tr>
</table>
</form>
</body>
</html>
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Ok, I know that the uploadDir from $uploaddir = '/public_html/Images'; is different from: $filePath = $uploadDir . $fileName;
But it seems to upload to my public_html when they don't match. When they match I get this error:
Warning: move_uploaded_file(): open_basedir restriction in effect. File(/public_html/Images/Sunset.jpg) is not within the allowed path(s): (/home/:/usr/:/tmp/) in /home/ravidtec/public_html/test4.php on line 38
Error uploading file
I've also made sure I gave 777 permissions on the images folder.
I've tried using, uploadDir = $_SERVER['DOCUMENT_ROOT'] . '/images/' ;
But that didn't work either, can anyone provide me some insight on my problem? Any help would be greatly appreciated.