DJThom
January 21, 2021, 5:55pm
1
djthomproductions.ga
I need to let one of my colleagues upload a file to the server
Hi there. I need to let one of my colleagues upload a file to the server, without giving him the FTP username and password. How can I do this? It there some sort of Softaculous script I can install? Is there any way of emailing the file to the server?
If your only uploading to a single directory, this tutorial will be fine, however you will to change the code around to allow all file types:
W3Schools offers free online tutorials, references and exercises in all the major languages of the web. Covering popular subjects like HTML, CSS, JavaScript, Python, SQL, Java, and many, many more.
2 Likes
The only issue with that is… You cannot change the php.ini
file.
Configure The “php.ini” File
First, ensure that PHP is configured to allow file uploads.
In your “php.ini” file, search for the file_uploads
directive, and set it to On:
file_uploads = On
Get them to email you the file, then you upload it. That is the only way i can think of.
.htaccess
php_value file_uploads On
upload.html
<html>
<head>
<title>Upload File</title>
<style>
input[type=file] {
width: 100%;
}
</style>
</head>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data">
<input name="MAX_FILE_SIZE" value="1000000" hidden>
<!-- MAX_FILE_SIZE is roughly 1 MB -->
File: <input name="userfile" type="file" id="userfie"><br>
<input type="submit" value="Submit!">
<input type="reset" value="Reset!">
</form>
</body>
</html>
upload.php
<html>
<head>
<title>Uploading...</title>
</head>
<body>
<h1 name="test">Uploading...</h1>
<?php
// List the allowed types.
$allow_type = array("text/html", "text/plain", "text/css", "text/js", "image/png", "image/jpg", "image/jpeg", "image/gif");
if ($_FILES['userfile']['error'] > 0) {
switch ($_FILES['userfile']['error']) {
case 1: echo 'File exceeded max file upload size';
break;
case 2: echo 'File exceeded max file size';
break;
case 3: echo 'File only partially uploaded';
break;
case 4: echo 'No file uploaded';
break;
case 6: echo 'No temp dir specified';
break;
case 7: echo 'Cannot write to disk';
break;
}
exit;
}
$test = false;
// Loop if correct MIME type.
for ($i = 0; $i > count($allow_type); $i++) {
if ($_FILES['userfile']['type'] == $allow_type[$i]) $test = true;
}
if (!$test) {
echo "Error: File type not allowed.";
exit;
}
// Put where you want the directory to be uploaded.
$upfile = '/uploads/' . $_FILES['userfile']['name'];
// Check if valid.
if (is_uploaded_file($_FILES['userfile']['tmp_name'])) {
if (!move_uploaded_file($_FILES['userfile']['tmp_name']) {
echo 'Could not move file.';
exit;
}
} else {
echo 'Possible file upload attack. Filename: '.$_FILES['userfile']['name'];
exit;
}
echo 'File uploaded successfully.<br>';
$contents = file_get_contents($upfile);
/** If you don't want HTML/PHP tags to be displayed, remove the
* comment of the line below.
$contents = strip_tags($contents);
**/
file_put_contents($_FILES['userfile']['name'], $contents);
// Preview
echo 'Preview of contents:<br>';
echo '<hr>';
echo $contents;
echo '<hr>';
// Use javascript to check.
echo '<script>';
echo 'var test = document.getElementsByName(\'test\');';
echo 'test.innerHTML = \'Completed!\';';
echo '</script>';
}
?>
</body>
</html>
This should help.
You dont need to. File uploads are already turned on.
4 Likes
@DJThom , after searching around a bit, I found this PHP script (which I have used before). It does not use FTP but allows you to manage files with configurable options:
2 Likes
DJThom
January 22, 2021, 9:07am
8
Thanks! I am logging on now, I will see if this is the solution to my problem.
3 Likes
system
Closed
February 6, 2021, 9:07am
9
This topic was automatically closed 15 days after the last reply. New replies are no longer allowed.