I have a site and i want users to have the option to upload files to my server. You know, like a text field, a Browse button and a Submit button. Now I know this must be done in the server side, but HOW exactly do i do this ??
Yes, and you'll also have to be running PHP 4.1.0 (due to the autoglobal $_FILES), so you might as well write it like this. (named upload.php, again... )
PHP Code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Upload a File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>
<head>
<title>Upload a File</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>
<body>
// If the user uploads not a valid image, then display an error msg.
$imgSize = @getImageSize($tmpname);
if (empty($imgSize)) {
print ("<p>Please upload a valid image.</p>\n");
} else {
/*** Get the mime type of the image and check, manager entered the valid image or not. ***/
$imageType = explode("/",$imgSize['mime']);
$imageType = trim(strtolower($imageType[1]));
$validImageTypes = array("jpg", "jpeg", "png", "gif"); // you can also use the same code for checking other type of files like, PDF.
if (!in_array($imageType, $validImageTypes)) {
print("<p>Please upload a valid image for cover.</p>\n");
} else {
if (move_uploaded_file($tmpname, $uploaddir . $name)) {
print ("<p>File Name: $name</p>\n");
print ("<p>File Size: $size</p>\n");
print ("<p>Your file was successfully uploaded!</p>\n");
} else {
print ("<p>Your file could not be uploaded.</p>");
}
}
}
}
These forms above works perfectly, I dont know anything about php but I was looking for something like this for some time. The only problem is that this form only works well whit files that has less then 3 MB and I needed one that can upload until 9 GB. Can you help me whit that?
I tank you in advance for the time dispended in reading this message, and hoppe to ear about you guys soon.
(obs): I'm Portuguese so I'm sorry about my rusty Inglish writing.
9 gig ? you will have to change options in your PHP.INI to allow for files that big.
Like I said previosly, I dont know how to program PHP, I just copy the form above and created an upload directory and it work, but only with files that has less than 2MB. Can you please help me with the ini.php?
Tank you, and sorry for being anoyng.
Bookmarks