I use this form
to upload an image to my PHP
:
<form method="post" action="http://my.domain/media.php" enctype="multipart/form-data">
<input type="hidden" name="MAX_FILE_SIZE" value="10485760" />
<input type="file" name="mediafile"></input>
<input type="submit"></input>
</form>
And I use this PHP
code to retrieve the uploaded file (image):
$mfn = "./upload_test.png";
if (move_uploaded_file($_FILES['mediafile']['tmp_name'], $mfn)) {
if (file_exists($mfn)) {
echo 'success';
} else {
echo 'Uploaded file didn\'t move to the requested path.';
print_r($_FILES);
}
} else {
echo 'move_uploaded_file error<br/>';
print_r(error_get_last());
echo '<br/>';
print_r($_FILES);
}
When I click the submit button, the move_uploaded_file
returns an error. So, I caught debug data with print_r(error_get_last())
:
Array (
[type] => 2
[message] => move_uploaded_file(): open_basedir restriction in effect. File() is not within the allowed path(s): (/home/username/:/tmp:/var/tmp:/usr/local/lib/php/)
[file] => /home/username/domains/my.domain/public_html/media.php
[line] => 96 )
and with print_r($_FILES)
:
Array (
[mediafile] => Array (
[name] => test.png
[type] => image/png
[tmp_name] => /tmp/phpvoQr3i
[error] => 0
[size] => 38207 )
)
NOTE: I can't edit php.ini or any admin settings.