|
Posted by Chris - SyracuseCS.com on 05/05/06 17:49
Here ya go. This is the script that I made for one of my sites. The
form takes the userid, and if the image gets uploaded ok it gets
renamed to useridu.jpg (100u.jpg) I only allow jpg's for this script.
It then gets inserted in an images table as unapproved (0). After I
approve the images the image gets renamed to userid.jpg (100.jpg) and
the users profile gets updated with the new picture.
Upload form
<?php
echo "Upload an image<br><br>";
echo "
<form action=\"uploader.php\" method=\"post\"
enctype=\"multipart/form-data\">
<input type=\"file\" name=\"file\" size=\"50\">
<br/>
<input type=\"submit\" value=\"Upload File\">
<input type='hidden' name='userid' value='$userid'>
</form>[ <a href=users.php class=\"menulink\">Back</a> ]<br><br>";
?>
uploader.php
<?php
global $userid;
if($file_name !="")
{
$image_type = strstr($file_name, '.');
if($image_type == ".jpg"){
$file_name = $userid."u.jpg";
copy ("$file", "/www/htdocs/user_images/$file_name") or die("Could
not copy file");
include "connect.php";
$result = mysql_query("INSERT INTO images (userid,name) VALUES
('$userid','$file_name')") or die ("Error in insert sql:".
mysql_error());
include "disconnect.php";
include("mem_header.php");
echo "Your file has been uploaded!<br><br>";
echo "<br>Your photo is pending approval<br><br>";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"2; URL=users.php\">";
include("mem_footer.php");
}else{
include("mem_header.php");
echo "Incorrect File Type. Your file must be a JPG<br><br>";
echo "Your file has NOT been uploaded!<br><br>";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"2;
URL=users.php?cmg=Upload\">";
include("mem_footer.php");
}
}
else {
include("mem_header.php");
echo "No file specified<br><br>";
echo "Your file has NOT been uploaded!<br><br>";
echo "<META HTTP-EQUIV=Refresh CONTENT=\"2;
URL=users.php?cmg=Upload\">";
include("mem_footer.php");
}
?>
Navigation:
[Reply to this message]
|