[PHP-DB] Image Uploading into Database with ID

2001-07-12 Thread Brad R. C.

I don't know how many of you are familiar with Vb (www.vbulletin.com) but I
am using the message board software and adding all that I can to it! :)

I am wanting my users to be able to add a photo to their profiles. So I am
trying to intergrate a upload script, that will upload the address to the
image (stored on the site) into the correct ID number of the user.

I have made it where it will upload the file to the correct folder and will
put a link in the database, but I cannot figure it all out. Listed below is
what I have in a .php file, but if you are familiar with the templates and
everything with vb, then I will post the code I have that is not working.

This code below works great.. but has not ability to add the image path or
anything to the correct user with ID.

--- code snippet = test.php ---
form enctype=multipart/form-data method=post  action=?php echo
$PHP_SELF ?
Upload a Photobr
input type=File name=picture size=25
brbr
input type=submit name=submit value=Upload
/form

?php
// Information needed to connect to the database
define(SQL_SERVER, localhost);
define(SQL_UID, USERNAME);
define(SQL_PWD, PASSWORD);
define(SQL_DB, DATABASE NAME);

// After the file has been chosen and they click submit this will happen
if ($submit) {

$connection = mysql_pconnect(SQL_SERVER, SQL_UID, SQL_PWD);

mysql_select_db(SQL_DB, $connection);

$sql = INSERT INTO user (picture_name) .
VALUES ('$picture_name');
mysql_query($sql);

exec(cp $picture /root/to/the/images/$picture_name);

// Echo's out the file that was upload to show that it succeeded.
echo temp file: $picturebr\n;
echo file name: $picture_namebr\n;
echo file size: $picture_sizebr\n;
echo file type: $picture_typebr\n;
echo br\n;
echo img src=images/$picture_namebr\n;

return 0;
}

?
--- code snippet = test.php ---

Here is what I altered the form code to look like for the modify and
registration templates.

--- code ---
tr bgcolor={firstaltcolor}
td valign=topnormalfontbUpload Picture :/bbr
smallfontPlease select a photo from your hard drive to post on the
site./smallfont/normalfont/td
td valign=topinput type=File class=bginput name=picture_name
size=25/td/tr
--- end code ---

I think for this to work properly it will have to not be called
picture_name but something along the lines of $bbuserinfo[picture_name]
to work... not for sure yet.


After that here is some of the code I have that replaces the submission part
of the above code. Since I added the form and everything to an already
existing if action statement I just added the below code to that but.. it
does not seem to work.

--- code ---
  // Photo Upload
  if ($picture_name !=) {
$picture_name=$picture_name;
exec(cp $picture /root/to/the/images/$picture_name);
  } else {
$picture_name=;
  }
  // End Photo Upload
--- end code ---

and for it to go along with the $bbuserinfo[picture_name] idea here is what
the code should look like :

--- code 
  // Photo Upload
  if ($bbuserinfo[picture_name] !=) {
$bbuserinfo[picture_name]=$bbuserinfo[picture_name];
exec(cp $picture /root/to/the/images/$picture_name);
  } else {
$bbuserinfo[picture_name]=;
  }
  // End Photo Upload
--- end code ---

The if action already looks for an ID.. if 0 it fails, else it continues...
so can anyone help me figure this one out... or tell me what a good command
is for selecting the ID out of the database for the user that is logged in..

thanks
BradC


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]




Re: [PHP-DB] Image Uploading into Database with ID

2001-07-12 Thread Jimmy Brake

Hi! so last night I asked is there/how do you do a ocifetchstatement in mysql no one 
responded..

so this is what I ended up doing.

function new_array($array)
{
// get the keys

$array2 = $array;
$keys = array_keys($array2);

// now use the keys to get the values

for($a=0;$acount($keys);$a++)
{
$the_key = $keys[$a];
$value = $array[$the_key];

// we got the value and the key now lets put em where we want em...

$new_array = array(
$keys[$a] = array(
0 = $value )
   );
$newer_array = array_merge_recursive($newer_array, $new_array);
}
return($newer_array);
}


function my_data_array($query,$link)
{
global $debug;
tracker($query);
$result = mysql_query($query, $link);
while($rows = mysql_fetch_array($result,MYSQL_ASSOC))
{
if(!$array)
{
$array=new_array($rows);
} else {
$array = array_merge_recursive($array, $rows);
}
}
return($array);
}

it returns an array that is just like the array returned from ocifetchstatement... so 
if you are migrating from oracle to mysql and you do not want to rewrite all our 
scripts... that use ocifetchstatement.

try this on for size

:-)

hope this helps someone and err saves them some time...

if anyone has a better way of doing this please send me the code.

Jimmy Brake


-- 
PHP Database Mailing List (http://www.php.net/)
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
To contact the list administrators, e-mail: [EMAIL PROTECTED]