Code: Select all
<?php
include("dbconnection/connect_db.inc.php");
if ($HTTP_POST_VARSї'submit']) {
print_r($HTTP_POST_FILES);
if (!is_uploaded_file($HTTP_POST_FILESї'file']ї'tmp_name'])) {
$error = "You did not upload a file!";
unlink($HTTP_POST_FILESї'file']ї'tmp_name']);
// assign error message, remove uploaded file, redisplay form.
} else {
//a file was uploaded
$maxfilesize=10240;
if ($HTTP_POST_FILESї'file']ї'size'] > $maxfilesize) {
$error = "file is too large";
unlink($HTTP_POST_FILESї'file']ї'tmp_name']);
// assign error message, remove uploaded file, redisplay form.
} else {
if ($HTTP_POST_FILESї'file']ї'type'] != "text/plain") {
$error = "This file type is not allowed";
unlink($HTTP_POST_FILESї'file']ї'tmp_name']);
// assign error message, remove uploaded file, redisplay form.
} else {
//File has passed all validation, copy it to the final destination and remove the temporary file:
copy($HTTP_POST_FILESї'file']ї'tmp_name'],"faqs/".$HTTP_POST_FILESї'file']ї'name']);
unlink($HTTP_POST_FILESї'file']ї'tmp_name']);
print "File has been successfully uploaded!";
exit;
}
}
}
}
?>
<html>
<head></head>
<body>
<form action="<?=$PHP_SELF?>" method="post" enctype="multipart/form-data">
<?=$error?>
<br><br>
Choose a file to upload:<br>
<input type="file" name="file"><br>
<input type="submit" name="submit" value="submit">
</form>
</body>
</html>Array ( [file] => Array ( [name] => dvdlist.txt [type] => text/plain [tmp_name] => /home/virtual/tmp/phpCAPTLV [error] => 0 [size] => 997 ) )
Warning: copy(faqs/dvdlist.txt): failed to open stream: Permission denied in /usr/home/virtual/bolt3.com/webroot/htdocs/uploadtest.php on line 24
File has been successfully uploaded!
Problem is, it isn't being uploaded because of the permission error. I know it's something to do with not having the FTP information but how do I give it that information so it can upload a txt file into this folder?
Thanks a lot. Any pointers on the script would be helpful too..