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, 09: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: 6
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 09:42 AM.

Reply With Quote
  #2  
Old July 14th, 2003, 08:35 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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, 09: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: 6
basically i just want to put a picture on every post..but make it different

Reply With Quote
  #4  
Old July 15th, 2003, 09: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: 653 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, 09: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: 6
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, 09:59 PM
FrankieShakes FrankieShakes is offline
Frank The Tank!
Dev Articles Beginner (1000 - 1499 posts)
 
Join Date: Jun 2002
Location: Toronto, Canada
Posts: 1,246 FrankieShakes User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 8
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, 11: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: 6
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, 11: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: 6
sorry...the problem is that i dont know how to select a picture instead of text

Reply With Quote
  #9  
Old July 16th, 2003, 08: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: 7
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, 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: 6
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, 12:20 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: 7
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, 12:34 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: 6
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