Profile Picture Question!
Posted: Tue Jan 17, 2012 12:45 pm
I was making the profile picture thing! Like...Uploading a profile picture and all!
It Always Shows "Your profile picture must be an image." even though I upload a picture!
Here are my edit_profile.php script!
[syntax=php]<?php
include('core/init.inc.php');
if (isset ($_POST ['email'], $_POST ['location'], $_POST ['about'])) {
$errors = array () ;
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)=== false) {
$errors [] = 'The email address you entered is invalid.' ;
}
if (preg_match('#^[a-z0-9]+$#i', $_POST['location']) === 0) {
$errors[] = 'Your location must only contain \'a-z\', \'0-9\' and spaces.' ;
}
if (empty($_FILES['avatar']['tmp_name']) === false) {
$file_ext = end(explode('.', $_FILES['avatar']['tmp_name'])) ;
if (in_array (strtolower($file_ext), array('jpg','jpeg','png','gif')) === false) {
$errors[] = 'Your profile picture must be an image.' ;
}
}
if (empty($errors)) {
set_profile_info ($_POST['email'],$_POST['about'],$_POST ['location'], (empty($_FILES['avatar']['tmp_name']) ? false : $_FILES['avatar']['tmp_name']));
}
$user_info = array (
$email => htmlentities($_POST ['email']),
$about => htmlentities($_POST ['about']),
$location => htmlentities($_POST ['location'])
) ;
} else {
$user_info = fetch_user_info ($_SESSION['uid']);
}
?>
<html>
<head></head>
<body>
<div>
<?php
if (isset ($errors)=== false) {
echo 'Click the update button to edit your profile.' ;
} else if (empty ($errors)){
echo 'Your profile has been updated.' ;
} else {
echo '<ul><li>', implode ('</li><li>', $errors), '</li></ul>' ;
}
?>
</div>
<form action="" method="POST" enctype = "multipart/form-data">
<div>
<label for="email">Email:</label>
<input type="text" name="email" id="email" value="<?php echo $_POST ['email'] ; ?>"/>
</div>
<div>
<label for="location">Location:</label>
<input type="text" name="location" id="location" value="<?php echo $_POST ['location'] ; ?>" />
</div>
<div>
<label for="about">About Me:</label>
<textarea name="about" id="about" rows="14" cols="50"><?php echo strip_tags($_POST ['about']) ; ?></textarea>
</div>
<div>
<label for="avatar">Avatar</label>
<input type="file" name="avatar" id="avatar" />
</div>
<div>
<input type="submit" value="Update"/>
</div>
</form>
</body>
</html>[/syntax]
It Always Shows "Your profile picture must be an image." even though I upload a picture!
Here are my edit_profile.php script!
[syntax=php]<?php
include('core/init.inc.php');
if (isset ($_POST ['email'], $_POST ['location'], $_POST ['about'])) {
$errors = array () ;
if (filter_var($_POST['email'], FILTER_VALIDATE_EMAIL)=== false) {
$errors [] = 'The email address you entered is invalid.' ;
}
if (preg_match('#^[a-z0-9]+$#i', $_POST['location']) === 0) {
$errors[] = 'Your location must only contain \'a-z\', \'0-9\' and spaces.' ;
}
if (empty($_FILES['avatar']['tmp_name']) === false) {
$file_ext = end(explode('.', $_FILES['avatar']['tmp_name'])) ;
if (in_array (strtolower($file_ext), array('jpg','jpeg','png','gif')) === false) {
$errors[] = 'Your profile picture must be an image.' ;
}
}
if (empty($errors)) {
set_profile_info ($_POST['email'],$_POST['about'],$_POST ['location'], (empty($_FILES['avatar']['tmp_name']) ? false : $_FILES['avatar']['tmp_name']));
}
$user_info = array (
$email => htmlentities($_POST ['email']),
$about => htmlentities($_POST ['about']),
$location => htmlentities($_POST ['location'])
) ;
} else {
$user_info = fetch_user_info ($_SESSION['uid']);
}
?>
<html>
<head></head>
<body>
<div>
<?php
if (isset ($errors)=== false) {
echo 'Click the update button to edit your profile.' ;
} else if (empty ($errors)){
echo 'Your profile has been updated.' ;
} else {
echo '<ul><li>', implode ('</li><li>', $errors), '</li></ul>' ;
}
?>
</div>
<form action="" method="POST" enctype = "multipart/form-data">
<div>
<label for="email">Email:</label>
<input type="text" name="email" id="email" value="<?php echo $_POST ['email'] ; ?>"/>
</div>
<div>
<label for="location">Location:</label>
<input type="text" name="location" id="location" value="<?php echo $_POST ['location'] ; ?>" />
</div>
<div>
<label for="about">About Me:</label>
<textarea name="about" id="about" rows="14" cols="50"><?php echo strip_tags($_POST ['about']) ; ?></textarea>
</div>
<div>
<label for="avatar">Avatar</label>
<input type="file" name="avatar" id="avatar" />
</div>
<div>
<input type="submit" value="Update"/>
</div>
</form>
</body>
</html>[/syntax]