wvmlt
11-29-2004, 04:34 AM
I have a form where users can upload an avatar
<form name="uploader" method="post" action="<? echo $PHP_SELF; ?>" enctype="multipart/form-data">
<input type="file" name="image" value="Browse">
<input type="submit" name="upload" value="Upload Image"><br><BR>
Maximum size and dimensions accepted are 20 KB and 100 X 100 pixels.
</form>
<?php
$domain = "mydomain.com";
$path_after_domain = "forum/uploads/";
if($_POST['upload']) {
if ($_FILES['image']['name'] == "") {
echo "Please select a file to upload!\n";
exit;
}
$uploads = "/home/mydomain/public_html/forum/uploads";
$types_array = array("image/gif","image/pjpeg","image/x-png");
if (!in_array($_FILES['image']['type'], $types_array)) {
echo "That file type is not allowed!\n";
exit;
}
$max_filesize = 20000;
if ($_FILES['image']['size'] > $max_filesize) {
echo "That file is too large!<br>The maximum file size allowed is 20 KB.\n";
exit;
}
$imagesize = getimagesize($_FILES['image']['tmp_name']);
$imagewidth = $imagesize[0];
$imageheight = $imagesize[1];
$maxwidth = 100;
$maxheight = 100;
if($imagewidth > $maxwidth || $imageheight > $maxheight) {
echo "That file is too large!<br>The maximum file size allowed is 100 X 100 pixels.\n";
exit;
}
move_uploaded_file($_FILES['image']['tmp_name'], "".$uploads."/".$_FILES['image']['name']) or die ("Couldn't upload file!");
echo "File uploaded";
echo "<br><br><img src=\"http://".$domain."/".$path_after_domain.$_FILES['image']['name']."\">";
echo "<br><br>h t tp://".$domain."/".$path_after_domain.$_FILES['image']['name']."";
}
?>
The database name is forum and the table name is users and the field where the avatar's url is stored is useravatar. How can I do this, so when a user uploads an avatar, the url is sent to the database
<form name="uploader" method="post" action="<? echo $PHP_SELF; ?>" enctype="multipart/form-data">
<input type="file" name="image" value="Browse">
<input type="submit" name="upload" value="Upload Image"><br><BR>
Maximum size and dimensions accepted are 20 KB and 100 X 100 pixels.
</form>
<?php
$domain = "mydomain.com";
$path_after_domain = "forum/uploads/";
if($_POST['upload']) {
if ($_FILES['image']['name'] == "") {
echo "Please select a file to upload!\n";
exit;
}
$uploads = "/home/mydomain/public_html/forum/uploads";
$types_array = array("image/gif","image/pjpeg","image/x-png");
if (!in_array($_FILES['image']['type'], $types_array)) {
echo "That file type is not allowed!\n";
exit;
}
$max_filesize = 20000;
if ($_FILES['image']['size'] > $max_filesize) {
echo "That file is too large!<br>The maximum file size allowed is 20 KB.\n";
exit;
}
$imagesize = getimagesize($_FILES['image']['tmp_name']);
$imagewidth = $imagesize[0];
$imageheight = $imagesize[1];
$maxwidth = 100;
$maxheight = 100;
if($imagewidth > $maxwidth || $imageheight > $maxheight) {
echo "That file is too large!<br>The maximum file size allowed is 100 X 100 pixels.\n";
exit;
}
move_uploaded_file($_FILES['image']['tmp_name'], "".$uploads."/".$_FILES['image']['name']) or die ("Couldn't upload file!");
echo "File uploaded";
echo "<br><br><img src=\"http://".$domain."/".$path_after_domain.$_FILES['image']['name']."\">";
echo "<br><br>h t tp://".$domain."/".$path_after_domain.$_FILES['image']['name']."";
}
?>
The database name is forum and the table name is users and the field where the avatar's url is stored is useravatar. How can I do this, so when a user uploads an avatar, the url is sent to the database