Uploading file problem
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
This is really beginning to pee me off. I've being working on this for about 2 hours
I have a form that I'm using to upload files from my drive to my site (For the avatar feature). I got the class to do that from PHPCLASSES.ORG.
The part that is annoying me is:
And the PHP for that is: (Quite long)
I want to make the avatar file thing optional... I can either make the script ignore the avatar if it's filled in or not, or make it required every time the whole form is filled in. I got the others optional (Upon change from default), but the avatar sh*t is driving me nuts!
I tried to do the following to see if the avatar is filled in, but I guess the input type 'file' doesn't send anything VIA $_POST, which is dumb, but $_FILES['hd_avatar'][0] (even though it gives 0 when the field is not filled in and 7 [or whatever] when the filled is filled in) doesn't work... that makes the script ignore the avatar entirely
Help on this would be greatly appreciated. Thanks.
I have a form that I'm using to upload files from my drive to my site (For the avatar feature). I got the class to do that from PHPCLASSES.ORG.
The part that is annoying me is:
Code: [ Select ]
File: <input type="file" name="hd_avatar" id="hda" size="25" />
And the PHP for that is: (Quite long)
PHP Code: [ Select ]
<?php
class ucp {
private $errors = 0;
/*
* function __construct( void )
*
* The construct function for the UCP class
*/
function __construct()
{
if(!isset($_SESSION['user']))
{
header("LOCATION: index.php");
}
}
/*
* function submit_account( string $email, string $conemail, string $pass, string $conpass, string $ola, string $hda, string $web, string $ctitle, string $msn, string $signature, string $allow_email, string $show_email, string $contact_choice)
* @string $email - User's email
* @string $conemail - Same user's email
* @string $pass - Users password
* @string $conpass - User's password retyped for confirmation
* @string $ola - User's avatar local to the website
* @string $hda - User's avatar from user's computer
* @string $web - User's website
* @string $ctitle - User's custom title
* @string $msn - User's MSN
* @string $signature - User's signature
* @string $allow_email - User's choice wether or not they want to get email from other users
* @string $show_email - User's choice wether they want their email to be securely shown
* @string $contact_choice - User's contact choice. Possible values:
* 1: PM
* 2: Email
* 3: Either
*
* Basically a construct function for the account form
*/
function submit_account($email, $conemail, $pass, $conpass, $ola, $hd_avatar, $web, $ctitle, $msn, $signature, $allow_email, $show_email, $contact_choice)
{
global $db;
// Initiating the return array
$return = array();
$reg_var = $db->_get_('email', USERS, array('UID' => $_SESSION['user']));
if($email != $reg_var)
{
$return[] = $this->update_email($_SESSION['user'], $email, $conemail);
}
if(!empty($pass))
{
$return[] = $this->update_password($_SESSION['user'], $pass, $conpass);
}
$reg_var = $db->_get_('avatar', USERS, array('UID' => $_SESSION['user']));
var_dump($_FILES['hd_avatar']);
if(sizeof($_FILES['hd_avatar'][0]) > 0)
{
$return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
}
$reg_var = $db->_get_('website', USERS, array('UID' => $_SESSION['user']));
if($web != $reg_var)
{
$return[] = $this->update_website($_SESSION['user'], $web);
}
$reg_var = $db->_get_('custom_title', USERS, array('UID' => $_SESSION['user']));
if($ctitle != $reg_var)
{
$return[] = $this->update_custom_title($_SESSION['user'], $ctitle);
}
$reg_var = $db->_get_('MSN', USERS, array('UID' => $_SESSION['user']));
if($msn != $reg_var)
{
$return[] = $this->update_msn($_SESSION['user'], $msn);
}
$reg_var = $db->_get_('signature', USERS, array('UID' => $_SESSION['user']));
if($signature != $reg_var)
{
$return[] = $this->update_signature($_SESSION['user'], $signature);
}
if($allow_email != 0)
{
$return[] = $this->allow_email($_SESSION['user'], $allow_email);
}
if($show_email != 0)
{
$return[] = $this->show_email($_SESSION['user'], $show_email);
}
if($contact_choice != 0)
{
$return[] = $this->contact_choice($_SESSION['user'], $contact_choice);
}
// Returning the results
if(sizeof($return) > 0)
{
if($this->errors > 0)
{
$type1 = ($errors > 1) ? "were" : 'was';
$type2 = ($errors > 1) ? "'s" : null;
$text = "<p>There $type1 $errors mistake$type2 in the form.</p>\n";
}
else
{
$text = "<p>Your form was successfully submitted and your profile was edited.</p>\n";
}
$text .= " <ul>\n";
foreach($return as $return_val)
{
$text .= " <li>$return_val</li>\n";
}
$text .= " </ul>\n";
return trim($text);
}
else
{
return "<p>No changes were made.</p>\n";
}
}
function update_email($uid, $email, $conemail)
{
global $db, $regex;
if($email != $conemail)
{
$this->errors +1;
return "Your email does not match your confirmation email.";
break;
}
if(!preg_match($regex['EMAIL'], $email) || !preg_match($regex['EMAIL'], $conemail))
{
$this->errors +1;
return "Your email are of incorrect type.";
break;
}
$sql = array(
'email' => $email,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "Email updated successfully";
}
}
function update_password($uid, $pass, $conpass)
{
global $db;
if($pass != $conpass)
{
$this->errors +1;
return "Your password does not match your confirmation password.";
}
$sql = array(
'password' => md5($pass),
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "Password updated successfully";
}
}
function update_avatar($uid, $ola, $hda, $reg_val)
{
global $db;
$handle = new upload($_FILES['hd_avatar']);
$username = $db->_get_('USERNAME', USERS, array('UID' => $_SESSION['user']));
$filed = "images/avatars/$username.JPG";
$unlink = true;
if(file_exists($filed))
{
if(unlink($filed))
{
$unlink = true;
}
}
if($handle->uploaded && $unlink == true)
{
$handle->file_new_name_body = $username;
$handle->file_new_name_ext = 'jpg';
$handle->image_resize = true;
$handle->image_x = 120;
$handle->image_ratio_y = true;
$handle->Process('images/avatars');
if(!$handle->processed) {
return $handle->error;
}
$handle-> Clean();
} else {
return $handle->error;
}
$sql = array(
'avatar' => "$username.JPG",
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return 'Your avatar was successfully updated.';
}
}
function update_website($uid, $web)
{
global $db, $regex;
$sql = array(
'website' => $web,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "Website updated successfully";
}
}
function update_custom_title($uid, $ctitle)
{
global $db;
$sql = array(
'custom_title' => $ctitle,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "Custom title updated successfully";
}
}
function update_msn($uid, $msn)
{
global $db;
$sql = array(
'MSN' => $msn,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "MSN updated successfully";
}
}
function allow_email($uid, $allow_email)
{
global $db;
$allow = (($allow_email == 1) ? 1 : 2);
$sql = array(
'allow_email' => $allow,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "You're email is now " . (($allow == 1) ? "allowed" : "not allowed");
}
}
function show_email($uid, $show_email)
{
global $db;
$show = (($show_email == 1) ? 1 : 2);
$sql = array(
'show_email' => $show,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "You're email is now " . (($show == 1) ? "public" : "not public");
}
}
function contact_choice($uid, $contact_choice)
{
global $db;
$choice = (($contact_choice == 1) ? 1 :
(($contact_choice == 2) ? 2 :
(($contact_choice == 3) ? 3 : 1)));
$contact = (($contact_choice == 1) ? 'PM' :
(($contact_choice == 2) ? 'Email' :
(($contact_choice == 3) ? 'PM and/or Email' : 'PM')));
$sql = array(
'contact_type' => $choice,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "You are going to be contacted by " . $contact . " from now on.";
}
}
function update_signature($uid, $signature)
{
global $db;
$sql = array(
'signature' => mysql_real_escape_string($signature),
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "You're signature was updated.";
}
}
}
class ucp {
private $errors = 0;
/*
* function __construct( void )
*
* The construct function for the UCP class
*/
function __construct()
{
if(!isset($_SESSION['user']))
{
header("LOCATION: index.php");
}
}
/*
* function submit_account( string $email, string $conemail, string $pass, string $conpass, string $ola, string $hda, string $web, string $ctitle, string $msn, string $signature, string $allow_email, string $show_email, string $contact_choice)
* @string $email - User's email
* @string $conemail - Same user's email
* @string $pass - Users password
* @string $conpass - User's password retyped for confirmation
* @string $ola - User's avatar local to the website
* @string $hda - User's avatar from user's computer
* @string $web - User's website
* @string $ctitle - User's custom title
* @string $msn - User's MSN
* @string $signature - User's signature
* @string $allow_email - User's choice wether or not they want to get email from other users
* @string $show_email - User's choice wether they want their email to be securely shown
* @string $contact_choice - User's contact choice. Possible values:
* 1: PM
* 2: Email
* 3: Either
*
* Basically a construct function for the account form
*/
function submit_account($email, $conemail, $pass, $conpass, $ola, $hd_avatar, $web, $ctitle, $msn, $signature, $allow_email, $show_email, $contact_choice)
{
global $db;
// Initiating the return array
$return = array();
$reg_var = $db->_get_('email', USERS, array('UID' => $_SESSION['user']));
if($email != $reg_var)
{
$return[] = $this->update_email($_SESSION['user'], $email, $conemail);
}
if(!empty($pass))
{
$return[] = $this->update_password($_SESSION['user'], $pass, $conpass);
}
$reg_var = $db->_get_('avatar', USERS, array('UID' => $_SESSION['user']));
var_dump($_FILES['hd_avatar']);
if(sizeof($_FILES['hd_avatar'][0]) > 0)
{
$return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
}
$reg_var = $db->_get_('website', USERS, array('UID' => $_SESSION['user']));
if($web != $reg_var)
{
$return[] = $this->update_website($_SESSION['user'], $web);
}
$reg_var = $db->_get_('custom_title', USERS, array('UID' => $_SESSION['user']));
if($ctitle != $reg_var)
{
$return[] = $this->update_custom_title($_SESSION['user'], $ctitle);
}
$reg_var = $db->_get_('MSN', USERS, array('UID' => $_SESSION['user']));
if($msn != $reg_var)
{
$return[] = $this->update_msn($_SESSION['user'], $msn);
}
$reg_var = $db->_get_('signature', USERS, array('UID' => $_SESSION['user']));
if($signature != $reg_var)
{
$return[] = $this->update_signature($_SESSION['user'], $signature);
}
if($allow_email != 0)
{
$return[] = $this->allow_email($_SESSION['user'], $allow_email);
}
if($show_email != 0)
{
$return[] = $this->show_email($_SESSION['user'], $show_email);
}
if($contact_choice != 0)
{
$return[] = $this->contact_choice($_SESSION['user'], $contact_choice);
}
// Returning the results
if(sizeof($return) > 0)
{
if($this->errors > 0)
{
$type1 = ($errors > 1) ? "were" : 'was';
$type2 = ($errors > 1) ? "'s" : null;
$text = "<p>There $type1 $errors mistake$type2 in the form.</p>\n";
}
else
{
$text = "<p>Your form was successfully submitted and your profile was edited.</p>\n";
}
$text .= " <ul>\n";
foreach($return as $return_val)
{
$text .= " <li>$return_val</li>\n";
}
$text .= " </ul>\n";
return trim($text);
}
else
{
return "<p>No changes were made.</p>\n";
}
}
function update_email($uid, $email, $conemail)
{
global $db, $regex;
if($email != $conemail)
{
$this->errors +1;
return "Your email does not match your confirmation email.";
break;
}
if(!preg_match($regex['EMAIL'], $email) || !preg_match($regex['EMAIL'], $conemail))
{
$this->errors +1;
return "Your email are of incorrect type.";
break;
}
$sql = array(
'email' => $email,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "Email updated successfully";
}
}
function update_password($uid, $pass, $conpass)
{
global $db;
if($pass != $conpass)
{
$this->errors +1;
return "Your password does not match your confirmation password.";
}
$sql = array(
'password' => md5($pass),
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "Password updated successfully";
}
}
function update_avatar($uid, $ola, $hda, $reg_val)
{
global $db;
$handle = new upload($_FILES['hd_avatar']);
$username = $db->_get_('USERNAME', USERS, array('UID' => $_SESSION['user']));
$filed = "images/avatars/$username.JPG";
$unlink = true;
if(file_exists($filed))
{
if(unlink($filed))
{
$unlink = true;
}
}
if($handle->uploaded && $unlink == true)
{
$handle->file_new_name_body = $username;
$handle->file_new_name_ext = 'jpg';
$handle->image_resize = true;
$handle->image_x = 120;
$handle->image_ratio_y = true;
$handle->Process('images/avatars');
if(!$handle->processed) {
return $handle->error;
}
$handle-> Clean();
} else {
return $handle->error;
}
$sql = array(
'avatar' => "$username.JPG",
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return 'Your avatar was successfully updated.';
}
}
function update_website($uid, $web)
{
global $db, $regex;
$sql = array(
'website' => $web,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "Website updated successfully";
}
}
function update_custom_title($uid, $ctitle)
{
global $db;
$sql = array(
'custom_title' => $ctitle,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "Custom title updated successfully";
}
}
function update_msn($uid, $msn)
{
global $db;
$sql = array(
'MSN' => $msn,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "MSN updated successfully";
}
}
function allow_email($uid, $allow_email)
{
global $db;
$allow = (($allow_email == 1) ? 1 : 2);
$sql = array(
'allow_email' => $allow,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "You're email is now " . (($allow == 1) ? "allowed" : "not allowed");
}
}
function show_email($uid, $show_email)
{
global $db;
$show = (($show_email == 1) ? 1 : 2);
$sql = array(
'show_email' => $show,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "You're email is now " . (($show == 1) ? "public" : "not public");
}
}
function contact_choice($uid, $contact_choice)
{
global $db;
$choice = (($contact_choice == 1) ? 1 :
(($contact_choice == 2) ? 2 :
(($contact_choice == 3) ? 3 : 1)));
$contact = (($contact_choice == 1) ? 'PM' :
(($contact_choice == 2) ? 'Email' :
(($contact_choice == 3) ? 'PM and/or Email' : 'PM')));
$sql = array(
'contact_type' => $choice,
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "You are going to be contacted by " . $contact . " from now on.";
}
}
function update_signature($uid, $signature)
{
global $db;
$sql = array(
'signature' => mysql_real_escape_string($signature),
);
$sql = $db->build_update(USERS, $sql, array('UID' => $uid));
if($db->set_result_resource($sql, true))
{
return "You're signature was updated.";
}
}
}
- <?php
- class ucp {
- private $errors = 0;
- /*
- * function __construct( void )
- *
- * The construct function for the UCP class
- */
- function __construct()
- {
- if(!isset($_SESSION['user']))
- {
- header("LOCATION: index.php");
- }
- }
- /*
- * function submit_account( string $email, string $conemail, string $pass, string $conpass, string $ola, string $hda, string $web, string $ctitle, string $msn, string $signature, string $allow_email, string $show_email, string $contact_choice)
- * @string $email - User's email
- * @string $conemail - Same user's email
- * @string $pass - Users password
- * @string $conpass - User's password retyped for confirmation
- * @string $ola - User's avatar local to the website
- * @string $hda - User's avatar from user's computer
- * @string $web - User's website
- * @string $ctitle - User's custom title
- * @string $msn - User's MSN
- * @string $signature - User's signature
- * @string $allow_email - User's choice wether or not they want to get email from other users
- * @string $show_email - User's choice wether they want their email to be securely shown
- * @string $contact_choice - User's contact choice. Possible values:
- * 1: PM
- * 2: Email
- * 3: Either
- *
- * Basically a construct function for the account form
- */
- function submit_account($email, $conemail, $pass, $conpass, $ola, $hd_avatar, $web, $ctitle, $msn, $signature, $allow_email, $show_email, $contact_choice)
- {
- global $db;
- // Initiating the return array
- $return = array();
- $reg_var = $db->_get_('email', USERS, array('UID' => $_SESSION['user']));
- if($email != $reg_var)
- {
- $return[] = $this->update_email($_SESSION['user'], $email, $conemail);
- }
- if(!empty($pass))
- {
- $return[] = $this->update_password($_SESSION['user'], $pass, $conpass);
- }
- $reg_var = $db->_get_('avatar', USERS, array('UID' => $_SESSION['user']));
- var_dump($_FILES['hd_avatar']);
- if(sizeof($_FILES['hd_avatar'][0]) > 0)
- {
- $return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
- }
- $reg_var = $db->_get_('website', USERS, array('UID' => $_SESSION['user']));
- if($web != $reg_var)
- {
- $return[] = $this->update_website($_SESSION['user'], $web);
- }
- $reg_var = $db->_get_('custom_title', USERS, array('UID' => $_SESSION['user']));
- if($ctitle != $reg_var)
- {
- $return[] = $this->update_custom_title($_SESSION['user'], $ctitle);
- }
- $reg_var = $db->_get_('MSN', USERS, array('UID' => $_SESSION['user']));
- if($msn != $reg_var)
- {
- $return[] = $this->update_msn($_SESSION['user'], $msn);
- }
- $reg_var = $db->_get_('signature', USERS, array('UID' => $_SESSION['user']));
- if($signature != $reg_var)
- {
- $return[] = $this->update_signature($_SESSION['user'], $signature);
- }
- if($allow_email != 0)
- {
- $return[] = $this->allow_email($_SESSION['user'], $allow_email);
- }
- if($show_email != 0)
- {
- $return[] = $this->show_email($_SESSION['user'], $show_email);
- }
- if($contact_choice != 0)
- {
- $return[] = $this->contact_choice($_SESSION['user'], $contact_choice);
- }
- // Returning the results
- if(sizeof($return) > 0)
- {
- if($this->errors > 0)
- {
- $type1 = ($errors > 1) ? "were" : 'was';
- $type2 = ($errors > 1) ? "'s" : null;
- $text = "<p>There $type1 $errors mistake$type2 in the form.</p>\n";
- }
- else
- {
- $text = "<p>Your form was successfully submitted and your profile was edited.</p>\n";
- }
- $text .= " <ul>\n";
- foreach($return as $return_val)
- {
- $text .= " <li>$return_val</li>\n";
- }
- $text .= " </ul>\n";
- return trim($text);
- }
- else
- {
- return "<p>No changes were made.</p>\n";
- }
- }
- function update_email($uid, $email, $conemail)
- {
- global $db, $regex;
- if($email != $conemail)
- {
- $this->errors +1;
- return "Your email does not match your confirmation email.";
- break;
- }
- if(!preg_match($regex['EMAIL'], $email) || !preg_match($regex['EMAIL'], $conemail))
- {
- $this->errors +1;
- return "Your email are of incorrect type.";
- break;
- }
- $sql = array(
- 'email' => $email,
- );
- $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
- if($db->set_result_resource($sql, true))
- {
- return "Email updated successfully";
- }
- }
- function update_password($uid, $pass, $conpass)
- {
- global $db;
- if($pass != $conpass)
- {
- $this->errors +1;
- return "Your password does not match your confirmation password.";
- }
- $sql = array(
- 'password' => md5($pass),
- );
- $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
- if($db->set_result_resource($sql, true))
- {
- return "Password updated successfully";
- }
- }
- function update_avatar($uid, $ola, $hda, $reg_val)
- {
- global $db;
- $handle = new upload($_FILES['hd_avatar']);
- $username = $db->_get_('USERNAME', USERS, array('UID' => $_SESSION['user']));
- $filed = "images/avatars/$username.JPG";
- $unlink = true;
- if(file_exists($filed))
- {
- if(unlink($filed))
- {
- $unlink = true;
- }
- }
- if($handle->uploaded && $unlink == true)
- {
- $handle->file_new_name_body = $username;
- $handle->file_new_name_ext = 'jpg';
- $handle->image_resize = true;
- $handle->image_x = 120;
- $handle->image_ratio_y = true;
- $handle->Process('images/avatars');
- if(!$handle->processed) {
- return $handle->error;
- }
- $handle-> Clean();
- } else {
- return $handle->error;
- }
- $sql = array(
- 'avatar' => "$username.JPG",
- );
- $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
- if($db->set_result_resource($sql, true))
- {
- return 'Your avatar was successfully updated.';
- }
- }
- function update_website($uid, $web)
- {
- global $db, $regex;
- $sql = array(
- 'website' => $web,
- );
- $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
- if($db->set_result_resource($sql, true))
- {
- return "Website updated successfully";
- }
- }
- function update_custom_title($uid, $ctitle)
- {
- global $db;
- $sql = array(
- 'custom_title' => $ctitle,
- );
- $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
- if($db->set_result_resource($sql, true))
- {
- return "Custom title updated successfully";
- }
- }
- function update_msn($uid, $msn)
- {
- global $db;
- $sql = array(
- 'MSN' => $msn,
- );
- $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
- if($db->set_result_resource($sql, true))
- {
- return "MSN updated successfully";
- }
- }
- function allow_email($uid, $allow_email)
- {
- global $db;
- $allow = (($allow_email == 1) ? 1 : 2);
- $sql = array(
- 'allow_email' => $allow,
- );
- $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
- if($db->set_result_resource($sql, true))
- {
- return "You're email is now " . (($allow == 1) ? "allowed" : "not allowed");
- }
- }
- function show_email($uid, $show_email)
- {
- global $db;
- $show = (($show_email == 1) ? 1 : 2);
- $sql = array(
- 'show_email' => $show,
- );
- $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
- if($db->set_result_resource($sql, true))
- {
- return "You're email is now " . (($show == 1) ? "public" : "not public");
- }
- }
- function contact_choice($uid, $contact_choice)
- {
- global $db;
- $choice = (($contact_choice == 1) ? 1 :
- (($contact_choice == 2) ? 2 :
- (($contact_choice == 3) ? 3 : 1)));
- $contact = (($contact_choice == 1) ? 'PM' :
- (($contact_choice == 2) ? 'Email' :
- (($contact_choice == 3) ? 'PM and/or Email' : 'PM')));
- $sql = array(
- 'contact_type' => $choice,
- );
- $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
- if($db->set_result_resource($sql, true))
- {
- return "You are going to be contacted by " . $contact . " from now on.";
- }
- }
- function update_signature($uid, $signature)
- {
- global $db;
- $sql = array(
- 'signature' => mysql_real_escape_string($signature),
- );
- $sql = $db->build_update(USERS, $sql, array('UID' => $uid));
- if($db->set_result_resource($sql, true))
- {
- return "You're signature was updated.";
- }
- }
- }
I want to make the avatar file thing optional... I can either make the script ignore the avatar if it's filled in or not, or make it required every time the whole form is filled in. I got the others optional (Upon change from default), but the avatar sh*t is driving me nuts!
I tried to do the following to see if the avatar is filled in, but I guess the input type 'file' doesn't send anything VIA $_POST, which is dumb, but $_FILES['hd_avatar'][0] (even though it gives 0 when the field is not filled in and 7 [or whatever] when the filled is filled in) doesn't work... that makes the script ignore the avatar entirely
Code: [ Select ]
if(count($_FILES['hd_avatar']['name']) > 0)
{
$return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
}
{
$return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
}
- if(count($_FILES['hd_avatar']['name']) > 0)
- {
- $return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
- }
Help on this would be greatly appreciated. Thanks.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- Anonymous
- Bot


- Joined: 25 Feb 2008
- Posts: ?
- Loc: Ozzuland
- Status: Online
May 15th, 2009, 11:02 pm
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
Nevermind, the following finally did the trick. About freaking time I tried that
Although I don't see how the other way didn't work...
Now I need to find a way to upload images from other sites (http://www.wedevoy.com/images/image.jpg), rather than always from hard drive. (As advanced as the class I got is, it doesn't do that
Code: [ Select ]
if(!empty($_FILES['hd_avatar']['name']))
{
$return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
}
{
$return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
}
- if(!empty($_FILES['hd_avatar']['name']))
- {
- $return[] = $this->update_avatar($_SESSION['user'], $ola, $hd_avatar, $reg_var);
- }
Although I don't see how the other way didn't work...
Now I need to find a way to upload images from other sites (http://www.wedevoy.com/images/image.jpg), rather than always from hard drive. (As advanced as the class I got is, it doesn't do that
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
The following doesn't do the trick.
Code: [ Select ]
$target_path = "images/avatars/";
$target_path = $target_path . basename($ola);
if(move_uploaded_file($ola, $target_path))
{
return "The file ". basename($ola). " has been uploaded";
}
else
{
return "There was an error uploading the file, please try again!";
}
$target_path = $target_path . basename($ola);
if(move_uploaded_file($ola, $target_path))
{
return "The file ". basename($ola). " has been uploaded";
}
else
{
return "There was an error uploading the file, please try again!";
}
- $target_path = "images/avatars/";
- $target_path = $target_path . basename($ola);
- if(move_uploaded_file($ola, $target_path))
- {
- return "The file ". basename($ola). " has been uploaded";
- }
- else
- {
- return "There was an error uploading the file, please try again!";
- }
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- joebert
- Sledgehammer


- Joined: Feb 10, 2004
- Posts: 13455
- Loc: Florida
- Status: Offline
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
- SpooF
- ٩๏̯͡๏۶


- Joined: May 22, 2004
- Posts: 3415
- Loc: Richland, WA
- Status: Offline
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
SpooF wrote:
This probably isnt the best way to go about this, but my first thought was to just run a wget command via exec
Sorry for my ignorance, but what command am I going to use? I have never really used CMD or linux stuff and don't know where to find the commands. Thanks.
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- SpooF
- ٩๏̯͡๏۶


- Joined: May 22, 2004
- Posts: 3415
- Loc: Richland, WA
- Status: Offline
'wget' is a command line program that retreives files from a web servers.
Usage:
You would probably do something like.
not 100% sure if that will work.
You might also be able to use http://us3.php.net/curl
Usage:
Code: [ Select ]
wget http://domain.com/somefile.etc
You would probably do something like.
Code: [ Select ]
exec('wget -P /your/absolute/path/goes/here/ '.$url);
not 100% sure if that will work.
You might also be able to use http://us3.php.net/curl
#define NULL (::rand() % 2)
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
SpooF wrote:
'wget' is a command line program that retreives files from a web servers.
Usage:
You would probably do something like.
not 100% sure if that will work.
Usage:
Code: [ Select ]
wget http://domain.com/somefile.etc
You would probably do something like.
Code: [ Select ]
exec('wget -P /your/absolute/path/goes/here/ '.$url);
not 100% sure if that will work.
How would I be able to rename that file and move it to a certain directory, and replace the file with the same name if it exists?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
- SpooF
- ٩๏̯͡๏۶


- Joined: May 22, 2004
- Posts: 3415
- Loc: Richland, WA
- Status: Offline
- Bogey
- Bogey


- Joined: Jul 14, 2005
- Posts: 8211
- Loc: USA
- Status: Offline
SpooF wrote:
Well you can download it to any folder you like, and you can easily rename it via rename - http://us2.php.net/rename
Thanks, I will try that
Just one more thing, how can I convert a file to jpg? Any image file? I don't know what it would be as I don't know what the user would submit, but I'd like to know how to convert images to jpg?
"Bring forth therefore fruits meet for repentance:" Matthew 3:8
Page 1 of 1
To Reply to this topic you need to LOGIN or REGISTER. It is free.
Post Information
- Total Posts in this topic: 12 posts
- Users browsing this forum: No registered users and 255 guests
- You cannot post new topics in this forum
- You cannot reply to topics in this forum
- You cannot edit your posts in this forum
- You cannot delete your posts in this forum
- You cannot post attachments in this forum
