Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
Can some modify this so...
Old 11-24-2009, 02:12 PM Can some modify this so...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Can somone modify this so it will resize ALL the images in a specific folder instead of just one? I haven't actually tested this script to see if it works with just one image, but assuming it does work that way, all I need done is make it work with a folder of images not just one image like it shows: $image = "../path/fileName.gif";

PHP Code:
<?php
$image 
"../path/fileName.gif";
if (
file_exists($image))
{
  list(
$width) = getimagesize($image);
  
// set the maximum width of the image here
  
$maxWidth 100;
  if (
$width $maxWidth)
  {
    echo 
"<p><img alt=\"Image\" width=\"$maxWidth\" src=\"$image\" />";
  }
  else
  {
    echo 
"<p><img alt=\"Image\" src=\"$image\" /></p>\n";
  }
}
else
{
  echo 
"<p>Image does not exist</p>";
}
?>
Thank you
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 11-24-2009 at 03:16 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 11-24-2009, 05:04 PM Re: Can some modify this so...
Bertjeuh's Avatar
Average Talker

Posts: 25
Name: Bert Van Leemput
Trades: 0
Are the names from the images random? Or is it just like:
1.jpg 2.jpg 3.jpg
__________________
There Are Only 10 Types of People in the World: Those Who Understand Binary, and Those Who Don't.
Bertjeuh is offline
Reply With Quote
View Public Profile
 
Old 11-24-2009, 05:10 PM Re: Can some modify this so...
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
PHP Code:
$dir '../path/';
$handle opendir($dir);
while(
$image readdir($handle))
{
     
//your existing code here

__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-24-2009, 05:42 PM Re: Can some modify this so...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
I tried as you said Null, and all I see is a blank white screen. I checked the code for syntax errors, but don't see any. :S
PHP Code:
<?php

$dir 
'/images/';
$handle opendir($dir);
while(
$image readdir($handle)) 

{
  list(
$width) = getimagesize($image);
  
// set the maximum width of the image here
  
$maxWidth 100;
  if (
$width $maxWidth)

  {
    echo 
"<p><img alt=\"Image\" width=\"$maxWidth\" src=\"$dir\" />";
  }
  else
  {
    echo 
"<p><img alt=\"Image\" src=\"$dir\" /></p>\n";
  }
}
else
{
  echo 
"<p>Image does not exist</p>";
}
?>
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 11-24-2009, 06:28 PM Re: Can some modify this so...
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
readdir returns the file name, not the full path. I think this should do it:
PHP Code:
<?php

$dir 
'/images/';
$handle opendir($dir);
while(
false !== ($image readdir($handle))) 

{
  list(
$width) = getimagesize($dir $image);
  
// set the maximum width of the image here
  
$maxWidth 100;
  if (
$width $maxWidth)

  {
    echo 
"<p><img alt=\"Image\" width=\"$maxWidth\" src=\"$dir\" />";
  }
  else
  {
    echo 
"<p><img alt=\"Image\" src=\"$dir\" /></p>\n";
  }
}
else
{
  echo 
"<p>Image does not exist</p>";
}
?>
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-24-2009, 07:02 PM Re: Can some modify this so...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Quote:
Originally Posted by NullPointer View Post
readdir returns the file name, not the full path. I think this should do it:
PHP Code:
<?php

$dir 
'/images/';
$handle opendir($dir);
while(
false !== ($image readdir($handle))) 

{
  list(
$width) = getimagesize($dir $image);
  
// set the maximum width of the image here
  
$maxWidth 100;
  if (
$width $maxWidth)

  {
    echo 
"<p><img alt=\"Image\" width=\"$maxWidth\" src=\"$dir\" />";
  }
  else
  {
    echo 
"<p><img alt=\"Image\" src=\"$dir\" /></p>\n";
  }
}
else
{
  echo 
"<p>Image does not exist</p>";
}
?>
Still getting a blank screen, not even echoing out an error. I think it's something with the readdir part, but not too sure, that's why I am asking...
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 11-24-2009, 10:10 PM Re: Can some modify this so...
NullPointer's Avatar
Will Code for Food

Posts: 2,815
Name: Matt
Location: Irvine, CA
Trades: 0
Try echoing $image to see if it is being set properly. Also, your last else condition (following the while loop) is not valid.
__________________

Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
NullPointer is online now
Reply With Quote
View Public Profile Visit NullPointer's homepage!
 
Old 11-25-2009, 08:05 AM Re: Can some modify this so...
Bertjeuh's Avatar
Average Talker

Posts: 25
Name: Bert Van Leemput
Trades: 0
Try this:

PHP Code:
<?php
$dir 
"images"//dir of your images
$exten "jpg"//extension -> jpg / gif / png
if ($handle = @opendir($dir)) 
{
    while (
false !== ($file = @readdir($handle))) { 
        
$bestand $dir ."/"$file;
        
$ext pathinfo($bestand);
        if(
$ext['extension'] == $exten)
        {
            echo 
"<p><img src='$bestand'></p>" ;
        }
    }
    @
closedir($handle); 
}
?>
If this works, you can set a max-width etc
__________________
There Are Only 10 Types of People in the World: Those Who Understand Binary, and Those Who Don't.
Bertjeuh is offline
Reply With Quote
View Public Profile
 
Old 11-25-2009, 11:01 AM Re: Can some modify this so...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Quote:
Originally Posted by Bertjeuh View Post
Try this:

PHP Code:
<?php
$dir 
"images"//dir of your images
$exten "jpg"//extension -> jpg / gif / png
if ($handle = @opendir($dir)) 
{
    while (
false !== ($file = @readdir($handle))) { 
        
$bestand $dir ."/"$file;
        
$ext pathinfo($bestand);
        if(
$ext['extension'] == $exten)
        {
            echo 
"<p><img src='$bestand'></p>" ;
        }
    }
    @
closedir($handle); 
}
?>
If this works, you can set a max-width etc
This works, but need to be able to set set max with and allow all 3 file types at the same time, not choose because the images are already in the directory as gif, jpg, png.

Thank you for you help Bertjeuh
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 11-25-2009, 11:06 AM Re: Can some modify this so...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Quote:
Originally Posted by NullPointer View Post
Try echoing $image to see if it is being set properly. Also, your last else condition (following the while loop) is not valid.
Tried that, not working either, should have thought of that right away, but it didn't work anyway.
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 11-25-2009, 01:18 PM Re: Can some modify this so...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
I would love to get one of these scripts working, any of you guys having any luck with them? Like I said, the one from nullpointer did not work at all (output was white screen) and the one from Bertjeuh echo's the image but doesn't resize and I tried putting the $maxwidth variable and couldn't get any output but a white screen.
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 11-25-2009, 02:28 PM Re: Can some modify this so...
Bertjeuh's Avatar
Average Talker

Posts: 25
Name: Bert Van Leemput
Trades: 0
PHP Code:
<?php
$dir 
"images"//dir of your images
$exten1 "jpg"//extension -> jpg / gif / png
$exten2 "png"//extension
$exten3 "gif"//extension
$maxwidth '100'//maximum widht
if ($handle = @opendir($dir)) 
{
    while (
false !== ($file = @readdir($handle))) { 
        
$bestand $dir ."/"$file;
        
$ext pathinfo($bestand);
        if(
$ext['extension'] == $exten1 || $ext['extension'] == $exten2 || $ext['extension'] == $exten3)
        {
            
$width getimagesize($bestand);
            if(
$width[0]<$maxwidth)
            {
                echo 
"<p><img src='$bestand'></p>" ;
            }
            else
            {
                echo 
"<p><img src='$bestand' width='$maxwidth'></p>";
            }
        }
    }
    @
closedir($handle); 
}
?>
__________________
There Are Only 10 Types of People in the World: Those Who Understand Binary, and Those Who Don't.
Bertjeuh is offline
Reply With Quote
View Public Profile
 
Old 11-25-2009, 04:43 PM Re: Can some modify this so...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
Wow, thanks Bertjeuh, that works! Happy Thanks Giving!
__________________
Made2Own

Please login or register to view this content. Registration is FREE
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 11-25-2009, 06:07 PM Re: Can some modify this so...
Brian07002's Avatar
Defies a Status

Posts: 2,162
Name: ...
Location: ...
Trades: 0
This isn't really that important, but is there another way to add alt text from a mysql table than this:

Code:
title=\"$row[element_1]\"
that way doesn't show anything...I am using firefox and have also tried alt in replace of title and that didn't work either, knowing already that alt is for ie browsers only.
__________________
Made2Own

Please login or register to view this content. Registration is FREE

Last edited by Brian07002; 11-25-2009 at 06:14 PM..
Brian07002 is offline
Reply With Quote
View Public Profile
 
Old 11-25-2009, 11:40 PM Re: Can some modify this so...
lizciz's Avatar
Super Spam Talker

Posts: 807
Name: Mattias Nordahl
Location: Sweden
Trades: 0
That should work. Right click on the website and check the source code to see if there's actually anything there, perhaps it has no value, as in title="".
__________________
Your answers will only be as good as your question. Formulate it well and give all the necessary information.
lizciz is offline
Reply With Quote
View Public Profile Visit lizciz's homepage!
 
Old 11-26-2009, 03:50 AM Re: Can some modify this so...
Novice Talker

Posts: 10
Name: Ashok
Trades: 0
Thanks mr Bertjeuh this coding is working fine.

Ashok kumar

Quote:
Originally Posted by Bertjeuh View Post
PHP Code:
<?php
$dir 
"images"//dir of your images
$exten1 "jpg"//extension -> jpg / gif / png
$exten2 "png"//extension
$exten3 "gif"//extension
$maxwidth '100'//maximum widht
if ($handle = @opendir($dir)) 
{
    while (
false !== ($file = @readdir($handle))) { 
        
$bestand $dir ."/"$file;
        
$ext pathinfo($bestand);
        if(
$ext['extension'] == $exten1 || $ext['extension'] == $exten2 || $ext['extension'] == $exten3)
        {
            
$width getimagesize($bestand);
            if(
$width[0]<$maxwidth)
            {
                echo 
"<p><img src='$bestand'></p>" ;
            }
            else
            {
                echo 
"<p><img src='$bestand' width='$maxwidth'></p>";
            }
        }
    }
    @
closedir($handle); 
}
?>
ashokkumarmba is offline
Reply With Quote
View Public Profile
 
Old 11-26-2009, 07:08 AM Re: Can some modify this so...
Novice Talker

Posts: 10
Name: Ashok
Trades: 0
PHP Code:
<?php
$dir 
"../images";
$extn1 "jpg";
$extn2 "png";
$extn3 "gif";
$maxwidth 100;


if(
$diropen opendir($dir))
{
    while(
false !==($file=readdir($diropen)))
    {
    
$best $dir ."/"$file;
    
$ext pathinfo($best);
        if(
$ext['extension'] == $extn1 || $ext['extension'] == $extn2 || $ext['extension'] == $extn3)
            {
                if(
$width $maxwidth)
                    {
                        echo 
"<p><img src=\"$best\" width=\"$width\"></p>";
                    }
                else
                    {
                        echo 
"<p><img src=\"$best\" height=\"100\" width=\"$maxwidth\"></p>";
                    }
            }
    }
closedir($diropen);
}
?>
I modified above code its also working fine.
ashokkumarmba is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Can some modify this so...
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.49077 seconds with 12 queries