File Uploading With Php

[Solved] File Uploading With Php | Php - Code Explorer | yomemimo.com
Question : Upload file in php

Answered by : olala-victor

<?php
// connect to the database
$conn = mysqli_connect('localhost', 'root', '', 'file-management');
// Uploads files
if (isset($_POST['save'])) { // if save button on the form is clicked // name of the uploaded file $filename = $_FILES['myfile']['name']; // destination of the file on the server $destination = 'uploads/' . $filename; // get the file extension $extension = pathinfo($filename, PATHINFO_EXTENSION); // the physical file on a temporary uploads directory on the server $file = $_FILES['myfile']['tmp_name']; $size = $_FILES['myfile']['size']; if (!in_array($extension, ['zip', 'pdf', 'docx'])) { echo "You file extension must be .zip, .pdf or .docx"; } elseif ($_FILES['myfile']['size'] > 1000000) { // file shouldn't be larger than 1Megabyte echo "File too large!"; } else { // move the uploaded (temporary) file to the specified destination if (move_uploaded_file($file, $destination)) { $sql = "INSERT INTO files (name, size, downloads) VALUES ('$filename', $size, 0)"; if (mysqli_query($conn, $sql)) { echo "File uploaded successfully"; } } else { echo "Failed to upload file."; } }
}

Source : https://codewithawa.com/posts/how-to-upload-and-download-files-php-and-mysql | Last Update : Sun, 15 May 22

Question : php upload file

Answered by : hungry-heron-1tl0sqpp65o7

<?php
$filename = basename($_FILES['myfile']['name']);
if (move_uploaded_file($_FILES['myfile']['tmp_name'], "files/$filename")) { echo "File uploaded";
} else { echo "An error occurred";
}
?>
<form action="<?php echo htmlspecialchars($_SERVER['REQUEST_URI']); ?>" method="post" enctype="multipart/form-data"> <label>File: <input type="file" name="myfile" /></label> <input type="submit" value="send" /> </form>

Source : https://wiki.weeklyd3.repl.co/index.php?title=PHP+for+Big+Nubs | Last Update : Thu, 14 Jul 22

Question : PHP File Upload

Answered by : naly-moslih

<!DOCTYPE html>
<html>
<body>
<form action="upload.php" method="post" enctype="multipart/form-data"> Select image to upload: <input type="file" name="fileToUpload" id="fileToUpload"> <input type="submit" value="Upload Image" name="submit">
</form>
</body>
</html>

Source : | Last Update : Mon, 30 May 22

Answers related to file uploading with php

Code Explorer Popular Question For Php