General Programming Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
 
User Name:
Password:
Remember me
 



Go Back   Dev Articles Community ForumsProgrammingGeneral Programming Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Display Modes
 
Unread Dev Articles Community Forums Sponsor:
  #1  
Old July 11th, 2003, 08:38 AM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
Making a different picture appear every new post

Sorry i forgot to read the forum instructinos. I based my clan member page on Matt Wade's news posting article; however, i can not figure out how to upload a different picture for each member that i post.

This is as far as ive gone with it and im still working on building the rest of the info. What im looking for is an option to browse for a picture when i post or something like that.

main posting file

PHP Code:
echo "<H1><u>Add News</u></H1>\n";
if(
$HTTP_POST_VARS['submit']) {
    if(
$HTTP_POST_VARS['password'] == 'pass') {
        if(!
$HTTP_POST_VARS['name']) {
            echo 
"You must enter a name";
            exit;
    }
    if(!
$HTTP_POST_VARS['age']) {
            echo 
"You must enter an age";
            exit;
        }
        if(
strstr($HTTP_POST_VARS['name'],"|")) {
            echo 
"Name cannot contain the pipe symbol - |";
            exit;
        }
        if(
strstr($HTTP_POST_VARS['yp'],"|")) {
            echo 
"News cannot contain the pipe symbol - |";
            exit;
    }
        if(
strstr($HTTP_POST_VARS['age'],"|")) {
            echo 
"News cannot contain the pipe symbol - |";
            exit;
        }
        
$fp fopen('../cgi-bin/news/news.txt','a');
        if(!
$fp) {
            echo 
"Error opening file!";
            exit;
        }
        
$line date("m.d.y") . "|" $HTTP_POST_VARS['name'];
        
$line .= "|" $HTTP_POST_VARS['age'];
    
$line .= "|" $HTTP_POST_VARS['yp'];
    
$line .= "|" $HTTP_POST_VARS['map'];
        
$line str_replace("\r\n","<BR>",$line);
        
$line .= "\r\n";
        
fwrite($fp$line);
        if(!
fclose($fp)) {
            echo 
"Error closing file!";
            exit;
        }
        echo 
"<b>News added!</b>\n";   
    } else {
        echo 
"Bad Password";
    }
}
?>
<FORM ACTION="<?=$PHP_SELF?>" METHOD="POST" NAME="newsentry">
Name:<BR>
<INPUT TYPE="text" SIZE="30" NAME="name"><BR>
Age:<BR>
<INPUT TYPE="text" SIZE="30" NAME="age"><BR>
Years Playing?:<BR>
<INPUT TYPE="text" SIZE="30" NAME="yp"><br>
Favorite Map:<BR>
<INPUT TYPE="text" SIZE="30" NAME="map"><BR><BR>
News Password:<BR>
<INPUT TYPE="password" SIZE="30" NAME="password"><BR>
<INPUT TYPE="submit" NAME="submit" VALUE="Post it!"><BR>
</FORM> 


thanks sorry for not reading rules the first time .

Last edited by Bruski : July 11th, 2003 at 08:42 AM.

Reply With Quote
  #2  
Old July 14th, 2003, 07:35 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 18
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Bruski,

Are you receiving any error messages at all?

Also, I'm having a hard time fully understanding what it is you're trying to do... Care to explain a little further?
__________________
____________________________________________
Developer Shed Weekly Writer | DevArticles Forum Moderator
Build Your Own KlipFolio Klip With PHP
FrankManno.com - Under Construction
Design Interactive Group - Under Construction

Reply With Quote
  #3  
Old July 15th, 2003, 08:18 PM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
basically i just want to put a picture on every post..but make it different

Reply With Quote
  #4  
Old July 15th, 2003, 08:24 PM
nicat23's Avatar
nicat23 nicat23 is offline
Addicted to Chaos..
Dev Articles Novice (500 - 999 posts)
 
Join Date: Jan 2003
Location: Ft. Worth, TX
Posts: 650 nicat23 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 1 h 48 m 34 sec
Reputation Power: 0
Send a message via AIM to nicat23 Send a message via Yahoo to nicat23
Have you thought about looking at some code that will randomly pick a picture out of a database maybe when you refresh?

Reply With Quote
  #5  
Old July 15th, 2003, 08:28 PM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
the problem is i dont have access to a database...i want to either manually upload a file or have it uploaded and call to it when i need it to display...i just dont know how

Reply With Quote
  #6  
Old July 15th, 2003, 08:59 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,240 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 18
Send a message via ICQ to FrankieShakes Send a message via MSN to FrankieShakes
Well, you have a few options... You don't necessarily need access to a database to achieve it.

In order to upload the file, you'll need to make use of PHP's file functions...

There's a good article on dealing with BLOBBING data to a database. Don't worry about how it interfaces with the database... What you should do is understand how the file manipulation is being done via the FORM... once the file is uploaded, you can use PHP's fopen() to open a file and write binary data to it.

As for randomizing the image on each page load, you can use Javascript to achieve that.

If you need help with that portion, let us know...

Reply With Quote
  #7  
Old July 15th, 2003, 10:23 PM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
i dont want to randomize it i want to be able to select it...and wheres the article...i alraedy know how to use ()fopen because i used a Matt Wades tutorial on news posting...

Reply With Quote
  #8  
Old July 15th, 2003, 10:23 PM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
sorry...the problem is that i dont know how to select a picture instead of text

Reply With Quote
  #9  
Old July 16th, 2003, 07:28 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to dhouston
I think I get what you're wanting: A guild user should be able to browse a directory for a single picture to insert into his profile. Here's some code that'll read image files in from a given directory and output a select box containing those values. If this isn't exactly what you need, you should be able to modify it pretty easily to suit your needs.

PHP Code:
<?php

$images
=array();
$imgpath='.';

if (
$handle opendir($imgpath)) {
    while (
false !== ($file readdir($handle))) {
        if (
preg_match("/\.jpg$|\.gif$|\.png$/i",$file)) {
          
array_push($images,$file);
        }
    }
    
closedir($handle);
}

print 
"<select name=\"theimage\">\n";
foreach(
$images as $i){
  print 
"\t<option value=\"" $i "\">" $i "</option>\n";
}
print 
"</select>\n";

?>

Reply With Quote
  #10  
Old July 16th, 2003, 11:08 AM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
k i get it but how do i display it i cant find a variable to display...i have 2 files one does th posting and one does the showing...sorry i feal like im asking too much...but so far what you have showed me it works i just want to get it showing..

Reply With Quote
  #11  
Old July 16th, 2003, 11:20 AM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to dhouston
Well, when you write to your flat file in the posting script, you'll want to add an item that's the name of the image selected by appending a "|" and the value of the select box to the end of the line. Then, when you display the page from your showing script, you'll just wrap the <img src=""> tag around the value given in the flat file.

Is it the case that you don't know how to read the flat file from the showing script? If so, just open the file and get the lines into an array. Then, for each line, use split() or explode() to split the values on the pipe character and put them into an array. You can then do a comparison of member id or name or whatever against the value in the appropriate array index to display the rest of the values. The more news items added, the bigger your file's going to be and the less efficient searching will be. Here's some pseudo code:

PHP Code:
 open $filename and put lines into $lines array;
foreach(
$lines as $line){
    
$vals=split("|",$line); // check parameter order at php.net
    
if($vals[0]==$search_criterion){
        print 
$vals[1] . "<br><br>";
    }



Here you can see, of course, that if you have multiple items submitted on a given date, you'll have problems selecting single articles out of the file. You really ought to include an auto-incrementing unique field to prevent these problems.

Reply With Quote
  #12  
Old July 16th, 2003, 11:34 AM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
sorry for the confusion but im not trying to search for the picture im just trying to diplay it...select..then display it.....

maybe this would be easier if i showed you the code...

ive applied what you have given me but cant seem to display the picture =[

PHP Code:
<?
if($action == "edit" && isset($HTTP_POST_VARS['password'])) {
    
//obviously you should change this password on the next line
    
if($HTTP_POST_VARS['password'] == "editpass") {
        
//First let's recompile that line with the pipe symbols so we can reinsert it
        
$line $HTTP_POST_VARS['date'] . "|" $HTTP_POST_VARS['name'];
        
$line .= "|" $HTTP_POST_VARS['age'];
    
$line .= "|" $HTTP_POST_VARS['yp'];
    
$line .= "|" $HTTP_POST_VARS['map'];
    
$line .= "|" $HTTP_POST_VARS['gun'];
        
$line str_replace("\r\n","<BR>",$line);
        
$line .= "\r\n";
        
$data file('../cgi-bin/news/news.txt');
        
$data[$id] = $line;
        
//the next line makes sure the $data array starts at the beginning
        
reset($data);
        
//now we open the file with mode 'w' which truncates the file
        
$fp fopen('../cgi-bin/news/news.txt','w');
        foreach(
$data as $element) {
            
fwrite($fp$element);
        }
        
fclose($fp);
        echo 
"Item Edited!<BR><BR>\n";
        echo 
"<a href=index.php?p=roster.php>Go Back</a>\n";
        exit;
    } else {
        echo 
"Bad password!\n";
        exit;
    }
}
if(
$action == "edit") {
    
$data file('../cgi-bin/news/news.txt');
    
$element trim($data[$id]);
    
$pieces explode("|"$element);
    
//the next line is to reverse the process of turning the end of lines into breaking returns
    
$news str_replace("<BR>","\r\n",$pieces[2]);
    echo 
"Make the changes you would like and press save.<BR>\n";
    
$images=array();

$imgpath='.';



if (
$handle opendir($imgpath)) {

    while (
false !== ($file readdir($handle))) {

        if (
preg_match("/.jpg$|.gif$|.png$/i",$file)) {

          
array_push($images,$file);

        }

    }

    
closedir($handle);

}



print 
"<select name=\"theimage\">\n";

foreach(
$images as $i){

  print 
"\t<option value=\"" $i "\">" $i "</option>\n";

}

print 
"</select>\n";

    echo 
"<FORM ACTION=\"$PHP_SELF?action=edit\" METHOD=\"POST\" NAME=\"editform\">\n";
    echo 
"Name:<BR>\n";
    echo 
"<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"name\" value=\"".$pieces[1]."\"><BR>\n";
    echo 
"Age:<BR>\n";
    echo 
"<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"age\" value=\"".$pieces[2]."\"><BR>\n";
    echo 
"Years Playing:<BR>\n";
    echo 
"<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"yp\" value=\"".$pieces[3]."\"><BR>\n";
    echo 
"Favorite Map:<BR>\n";
    echo 
"<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"map\" value=\"".$pieces[4]."\"><BR>\n";
    echo 
"Favorite Gun:<BR>\n";
    echo 
"<INPUT TYPE=\"text\" SIZE=\"30\" NAME=\"gun\" value=\"".$pieces[5]."\"><BR>\n";
    echo 
"Password:<BR>\n";
    echo 
"<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
    echo 
"<INPUT TYPE=\"hidden\" NAME=\"date\" VALUE=\"".$pieces[0]."\">\n";
    echo 
"<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
    echo 
"<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Save\"><BR>\n";
    echo 
"</FORM>\n";
    exit;
}
if(
$action == "delete" && isset($HTTP_POST_VARS['password'])) {
    
//obviously you should change this password on the next line
    
if($HTTP_POST_VARS['password'] == "deletepass") {
        
$data file('../cgi-bin/news/news.txt');
        
//this next line will remove the single news item from the array
        
array_splice($data,$id,1);
        
//now we open the file with mode 'w' which truncates the file
        
$fp fopen('../cgi-bin/news/news.txt','w');
        foreach(
$data as $element) {
            
fwrite($fp$element);
        }
        
fclose($fp);   
        echo 
"Item deleted!<BR><BR>\n";   
    echo 
"<a href=index.php?p=roster.php>Go Back</a>\n";
        exit;
    } else {
        echo 
"Bad password!\n";
        exit;
    }
}
if(
$action == "delete") {
    echo 
"<H2>Delete News?</H2>\n";
    
$data file('../cgi-bin/news/news.txt');
    
$element trim($data[$id]);
    
$pieces explode("|"$element);
    echo 
$pieces[1] . "<BR>" $pieces[2] . "<BR>" $pieces[3] . "<BR>" $pieces[4]. "<BR>" $pieces[5]. "</b>\n";
    echo 
"<BR><BR>\n";
    echo 
"Are you sure you want to delete this news item? If so, enter the password and click on Delete.<BR>\n";
    echo 
"<FORM ACTION=\"$PHP_SELF?action=delete\" METHOD=\"POST\" NAME=\"deleteform\">\n";
    echo 
"Password:<BR>\n";
    echo 
"<INPUT TYPE=\"password\" SIZE=\"30\" NAME=\"password\"><BR>\n";
    echo 
"<INPUT TYPE=\"hidden\" NAME=\"id\" VALUE=\"$id\">\n";
    echo 
"<INPUT TYPE=\"submit\" NAME=\"submit\" VALUE=\"Delete\"><BR>\n";
    echo 
"</FORM>\n";
    exit;
}
echo 
"<H1><u>Current Roster</u></H1>\n";
$data file('../cgi-bin/news/news.txt');
//next line removed to make everything else easier in the admin script
//$data = array_reverse($data);
foreach($data as $key=>$element) {
    
$element trim($element);
    
$pieces explode("|"$element);

    echo 
"<center><table cellspacing=0 cellpadding=0 cellwall=o border=0><tr><td><img src=template/name.gif></td><td 

width=200>" 
$pieces[1] . "</td><td td bgcolor=#E2E2E2><img src=template/age.gif></td><td bgcolor=#E2E2E2 width=200>" 

$pieces[2] . "</td></tr><tr><td bgcolor=#E2E2E2><img src=template/yp.gif></td><td width=200 bgcolor=#E2E2E2 >" 

$pieces[3] . "</td><td><img src=template/map.gif></td><td width=200>" $pieces[4] . "</td></tr><tr><td><img 

src=template/gun.gif></td><td>" 
$pieces[5]  . "</td></tr></table>" "</b>\n";
    echo 
"<br> <a href=roster.php?action=delete&id=$key>Delete</a>\n";
    echo 
"<a href=roster.php?action=edit&id=$key>Edit</a>\n";
    echo 
"<a href=addmem.php>Add</a>\n";
    echo 
"<BR><BR>\n";
}
?>


thanks again...i just need the variable to display in the way the others are shown or a different way.

Reply With Quote
  #13  
Old July 16th, 2003, 11:35 AM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
i used Matt Wades tutorial ....Thanks Mr.Wade

Reply With Quote
  #14  
Old July 16th, 2003, 12:00 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to dhouston
In the first block of code, when you're writing values to the file, add the following line:

PHP Code:
 $line .= "|" $HTTP_POST_VARS['theimage']; 


after

PHP Code:
 $line .= "|" $HTTP_POST_VARS['gun']; 


Then, when you want to display the image in the lower code block, pull the image name out as $pieces[6]. That'll contain only the filename. You'll need to prepend the http path and the appropriate HTML tags to display the image. I can't spell it out any more clearly.

Reply With Quote
  #15  
Old July 16th, 2003, 12:08 PM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
thx u =]

Reply With Quote
  #16  
Old July 16th, 2003, 12:21 PM
Bruski Bruski is offline
Contributing User
Dev Articles Newbie (0 - 499 posts)
 
Join Date: Jul 2003
Location: Toronto, Canada
Posts: 192 Bruski User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 16
sorry to bug you again...i know this might be getting a bit frustrating ...but i did what you asked me to do and it doesnt display the picture...when i go to the website and try to see if the picture has any info it says no info available like i havent selected a picture...so i dont know...

http://bruski.recongamer.com/al/

its at roster

Reply With Quote
  #17  
Old July 16th, 2003, 12:59 PM
dhouston's Avatar
dhouston dhouston is offline
Contributing User
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: May 2003
Location: Tennessee
Posts: 1,355 dhouston User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 17
Send a message via ICQ to dhouston
Did you actually upload images into the appropriate directory and update the flat file appropriately? If there's no value in the flat file corresponding to an image, an image can't be displayed. Try uploading an image to whatever directory you're specifying in $imgpath and editing one line of the flat file by adding "|imagename.ext" where imagename.ext is the name of the image you uploaded. That should work.

Then, when you're displaying the page by using the $pieces array, do a test:

PHP Code:
if($pieces[6]){
    
//print your image code;
}
else{
    
//optionally print a default image


Reply With Quote
Reply

Viewing: Dev Articles Community ForumsProgrammingGeneral Programming Help > Making a different picture appear every new post


Developer Shed Advertisers and Affiliates


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.

© 2003-2018 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap