Yenaa
kid a
- Pronoun
- he
So I've been working on using PHP to make a user control panel for a project for my site. I got the profile to work just I wanted it to, but am having a bit of a problem with avatars. Basically, I'm using this form to upload the image to my server:
and this form as the action, which uploads the file to my server.
It functions properly. It saves the uploaded avatar into a folder, then rewrite's the user's avatar. However, it works in a way that makes hundreds of unused avatars left in my avatar folder. Is there a way to make only one of these avatars per user or to delete the last avatar?
PHP:
<form enctype="multipart/form-data" action="uploader_avatar.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file to upload: <input name="uploadedfile" type="file" /><br />
<input type="submit" value="Upload File" />
</form>
and this form as the action, which uploads the file to my server.
PHP:
<?php
include "init.php";
$target_path = "avatars/";
$uploads = $_FILES['uploadedfile'];
$uploads = addslashes(mysql_escape_string($_FILES['uploadedfile']));
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
$current = mysql_query("SELECT * FROM user WHERE username='".$_SESSION['username']."'");
$current = mysql_fetch_array($current);
$replace = mysql_query("UPDATE user SET avatar='http://ds.rothion.com/Art Boards/avatars/". basename( $_FILES['uploadedfile']['name']). "' WHERE username='".$_SESSION['username']."'");
$replace = mysql_fetch_array($replace);
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['uploadedfile']['name']).
" has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}
?>
It functions properly. It saves the uploaded avatar into a folder, then rewrite's the user's avatar. However, it works in a way that makes hundreds of unused avatars left in my avatar folder. Is there a way to make only one of these avatars per user or to delete the last avatar?