Page 1 of 2
Couple questions..
Posted: Mon Oct 27, 2003 11:26 am
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!

Posted: Mon Oct 27, 2003 11:35 am
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 />';
}
}
?>
Posted: Mon Oct 27, 2003 11:39 am
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?
Posted: Mon Oct 27, 2003 11:56 am
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
Posted: Mon Oct 27, 2003 12:11 pm
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");
?>
Posted: Mon Oct 27, 2003 12:19 pm
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?

Posted: Mon Oct 27, 2003 12:25 pm
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
Posted: Mon Oct 27, 2003 12:30 pm
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?
Posted: Mon Oct 27, 2003 12:31 pm
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..

Posted: Mon Oct 27, 2003 12:35 pm
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]);
Posted: Mon Oct 27, 2003 12:41 pm
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.
Posted: Mon Oct 27, 2003 1:06 pm
by nick2
SOLUTION:
I talk to my host.. they're disabling safe_mode on my website.
hehe
Posted: Mon Oct 27, 2003 1:20 pm
by volka
they might consider su-exec instead of safe-mode (if it sounds like a rant against safe-mode: yes. it really is

)
Posted: Mon Oct 27, 2003 4:09 pm
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
Posted: Mon Oct 27, 2003 5:13 pm
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)