Hi,
I am lost when I need to upload some files, I feel lost
as I can't figure out what to do.
Can someone offer some advice, I really would appreciate
the help!!
Hi,
I am lost when I need to upload some files, I feel lost
as I can't figure out what to do.
Can someone offer some advice, I really would appreciate
the help!!
There are two different things people mean by "upload": transferring files to a hosting account (FTP/SFTP or a host file manager) and building a web form that accepts files (PHP). As asked, clarifying which of those is needed is the first step. 's W3Schools pointer is a quick start; for definitive details and security guidance consult the PHP manual and OWASP.
PHP file upload manual
OWASP: Unrestricted File Upload
Minimal example (HTML form + PHP handler):
<form method="post" enctype="multipart/form-data" action="upload.php">
<input type="file" name="file">
<input type="submit" value="Upload">
</form> <?php
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_FILES['file'])) {
$f = $_FILES['file'];
if ($f['error'] !== UPLOAD_ERR_OK) exit;
$finfo = new finfo(FILEINFO_MIME_TYPE);
$mime = $finfo->file($f['tmp_name']);
$allowed = ['image/jpeg' => 'jpg', 'image/png' => 'png'];
if (!isset($allowed[$mime])) exit;
$name = bin2hex(random_bytes(8)) . '.' . $allowed[$mime]; // PHP 7+
$dir = __DIR__ . '/uploads';
if (!is_dir($dir)) mkdir($dir, 0755, true);
move_uploaded_file($f['tmp_name'], $dir . '/' . $name);
}
?> Quick checklist and cautions: decide FTP vs PHP first; for FTP prefer SFTP/FTPS or a host file manager for simple file transfers; for PHP check php.ini (file_uploads, upload_max_filesize, post_max_size), inspect $_FILES[...]['error'], ensure the upload directory is writable but not executable, validate MIME with finfo, sanitize or replace filenames (use random names), block execution of uploaded files (store outside web root or add server rules), and consult server error logs when uploads fail. See the PHP manual and OWASP link above for details.
Jump to Post— chrishea 182Please be more specific. Are you trying to upload programs and images to the server (i.e. FTP) or are you trying to write a PHP program to do uploads?
Please be more specific. Are you trying to upload programs and images to the server (i.e. FTP) or are you trying to write a PHP program to do uploads?
We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.