I am using the following code to upload an image.
1). can this code be made better?
2). how do I link the uploaded image to the user uploading the image. e.g. to bring it up later
<?php
// In PHP earlier then 4.1.0, $HTTP_POST_FILES should be used instead of $_FILES
if($_FILES['userfile']['name'] == '') {
echo 'You did not select a photo to upload';
}
elseif($_FILES['userfile']['size'] == 0) {
echo 'There appears to be a problem with the photo your are uploading';
}
elseif($_FILES['userfile']['size'] > $MAX_FILE_SIZE) {
echo 'The photo you selected is too large';
}
elseif(!getimagesize($_FILES['userfile']['tmp_name'])) {
echo 'The photo you selected is not a valid image file';
}
else {
$uploaddir = 'seller_images/'; // remember the trailing slash!
$uploadfile = $uploaddir. $_FILES['userfile']['name'];
if(move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) {
echo 'Upload file success!';
}
else {
echo 'There was a problem uploading your file.<br>';
print_r($_FILES);
}
}
?>