Couple questions..

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Couple questions..

Post by nick2 »

1:
Is there a way to make this display only .jpg. bmp and .gif?

because its displaying folders aswell "_vti_cnf"

heres the code:

Code: Select all

<td width="100%"><form method="POST" action="removep.php">
<? $dir = $_COOKIE[user];
$dh = opendir($dir); // open it for reading 
while (($file = readdir($dh)) !== false) { // loop files 
if (($file != ".") and ($file != "..")) {
        echo "<center><table border="0">
<tr><td><a href="http://www.slices.net/$dir/$file"><img height="50" width="50" border="0" src="".$dir."/".$file.""></td></tr>
<tr><td><center><b>$file</b></center></td></tr></table>";
     } 
}
second code:

Code: Select all

$dir = $_COOKIE[user];
$dh = opendir($dir); // open it for reading 
echo '<form method="POST" action="removep.php">
<select name="delete">'; // html 
while (($file = readdir($dh)) !== false) { // loop files 
if (($file != ".") and ($file != "..")) {
        echo "\n".' <option>' . $file .'</option>'; // each image html 
     } 
} 
echo '</select><input type="submit" value="Delete" name="B1"></form>'; // end html
?>

</form></td>
  </tr>
</table>
second question:
I'm sure i'll have one soon..


Thanks! :wink:
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

if (($file != ".") and ($file != "..")) {
this prevents the folders . and .. from beeing displayed. You need something similar for the file's extension (if you want to rely on the name). Instead of using more and more if-cases you might set up an array containing the allowed extensions

Code: Select all

<?php

$allowedExtensions = array('.jpg', '.jpeg', '.png', '.bmp');

$dir = './'; // the trailing / is important to make $dir.$filename a valid path
$dh = opendir($dir); // open it for reading
while (($filename = readdir($dh)) !== false)
{ // loop files
	if (is_file($dir.$filename)) // skip directories, filters out . and .. as well
	{
		$extension = strrchr($filename, '.');
		if (in_array($extension, $allowedExtensions))
			echo $filename, '<br />';
	}
}
?>
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

Ok instead of that I just relized I could filter that folder name since thats the only folder in there.

Ok second question.. is there a way to add text to an image then save it?

like to make a banner?
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

volka wrote:
if (($file != ".") and ($file != "..")) {
this prevents the folders . and .. from beeing displayed. You need something similar for the file's extension (if you want to rely on the name). Instead of using more and more if-cases you might set up an array containing the allowed extensions

Code: Select all

<?php

$allowedExtensions = array('.jpg', '.jpeg', '.png', '.bmp');

$dir = './'; // the trailing / is important to make $dir.$filename a valid path
$dh = opendir($dir); // open it for reading
while (($filename = readdir($dh)) !== false)
{ // loop files
	if (is_file($dir.$filename)) // skip directories, filters out . and .. as well
	{
		$extension = strrchr($filename, '.');
		if (in_array($extension, $allowedExtensions))
			echo $filename, '<br />';
	}
}
?>
ONE POSSIBLE ISSUE, DOES THAT INCLUDE CASES LIKE: BLAH.10.27.2003.JPG


sorry bout the caps, but i feel that if this is a newbie, it's important to point out that (s)he needs to think about little things like that
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

Guys I got past that thanks.. but i'm having trouble using rmdir()

I am trying to delete this image but get this, btw yes i did set the folder permissions to 777!

Code: Select all

/mom/b-weed.jpg
Warning: rmdir(): SAFE MODE Restriction in effect. The script whose uid is 511 is not allowed to access / owned by uid 0 in /home/virtual/site9/fst/var/www/html/removep.php on line 3

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site9/fst/var/www/html/removep.php:2) in /home/virtual/site9/fst/var/www/html/removep.php on line 4
please help..

the code:

Code: Select all

<?php
print "/" . $_COOKIE[user] . "/" . $_POST[delete];
rmdir("/" . $_COOKIE[user] . "/" .$_POST[delete]);
header("location: Http://www.slices.net/pictures.php");
?>
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

m3rajk wrote:ONE POSSIBLE ISSUE, DOES THAT INCLUDE CASES LIKE: BLAH.10.27.2003.JPG


sorry bout the caps, but i feel that if this is a newbie, it's important to point out that (s)he needs to think about little things like that
ok

Code: Select all

<?php
$filename = 'BLAH.10.27.2003.JPG';
$extension = strtolower( strrchr($filename, '.') );

echo $extension;
?>
satisfied? ;)
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

volka wrote:
m3rajk wrote:ONE POSSIBLE ISSUE, DOES THAT INCLUDE CASES LIKE: BLAH.10.27.2003.JPG


sorry bout the caps, but i feel that if this is a newbie, it's important to point out that (s)he needs to think about little things like that
ok

Code: Select all

<?php
$filename = 'BLAH.10.27.2003.JPG';
$extension = strtolower( strrchr($filename, '.') );

echo $extension;
?>
satisfied? ;)
i'm not.. I would really like an answer on why this might be happening.. *look above at my post*
lol
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

sorry, don't know anything about safe mode except I despise it ;)
print "/" . $_COOKIE[user] . "/" . $_POST[delete];
is the directory you want to access really located there? an absolute path?
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

well removep.php is in my html folder.. then from there user cookie is the name of the folder in this case mom so: /mom/ then we have the file we want deleted.. which is weed-b.jpg so: /mom/weed-b.jpg

but it says that error.. :(
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

so the absolute path you want to access is /home/virtual/site9/fst/var/www/html/mom/b-weed.jpg?
If so try it without the leading / in rmdir("/" . $_COOKIE[user] . "/" .$_POST[delete]);
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

If I take away the "/" it says the directory doesn';t exsist.. so I think i should stick with the safe mode error cuz theres a solution to it somewhere.
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

SOLUTION:

I talk to my host.. they're disabling safe_mode on my website. :)

hehe
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

they might consider su-exec instead of safe-mode (if it sounds like a rant against safe-mode: yes. it really is ;) )
User avatar
nick2
Forum Contributor
Posts: 118
Joined: Fri Jul 25, 2003 2:34 pm

Post by nick2 »

why won't this work?

code:

Code: Select all

<?php
unlink("/" . $_COOKIE[user] . "/" . $_POST[delete]);
header("location: Http://www.slices.net/pictures.php");
?>
errror:

Warning: unlink(/mom/avatar1.jpg): No such file or directory in /home/virtual/site9/fst/var/www/html/removep.php on line 2

Warning: Cannot modify header information - headers already sent by (output started at /home/virtual/site9/fst/var/www/html/removep.php:2) in /home/virtual/site9/fst/var/www/html/removep.php on line 3
m3rajk
DevNet Resident
Posts: 1191
Joined: Mon Jun 02, 2003 3:37 pm

Post by m3rajk »

volka wrote:
m3rajk wrote:ONE POSSIBLE ISSUE, DOES THAT INCLUDE CASES LIKE: BLAH.10.27.2003.JPG


sorry bout the caps, but i feel that if this is a newbie, it's important to point out that (s)he needs to think about little things like that
ok

Code: Select all

<?php
$filename = 'BLAH.10.27.2003.JPG';
$extension = strtolower( strrchr($filename, '.') );

echo $extension;
?>
satisfied? ;)
actually i was thinking preg_match('/\.jp(e|g)g?$/i' $file); sinve that makes it have to end with .jpe.jpg, jpeg since those are valid jpg extensions (yes thereis one fake extension that would be allowed.....jpgg)
Post Reply