Re: [PHP] Opensource webshop

2005-09-22 Thread Vince LaMonica
On Fri, 23 Sep 2005, Jasper Bryant-Greene wrote:

} > > There are probably dozens of free open source PHP carts already out
} > > there.  Not to mention the ones written in Perl.
} > > 
} > Are there many in just PHP to?
} 
} As he said, there are probably dozens. Four of the PHP-based ones are listed
} under "e-Commerce" on this website:
} 
} http://www.opensourcecms.com/

A few more PHP ones [including the 4 at the above URL]:

http://www.shop-script.com/php-shopping-cart-software-1.html
http://www.zen-cart.com/
http://www.oscommerce.com/
http://www.x-cart.com/articles/x-cart_open_source.html
http://creloaded.com/index.php
http://www.osc2nuke.com/
http://cpcommerce.org/
http://www.cubecart.com/site/home/ [not OSS, but free if (c) is not 
modified]
http://siliconsys.com/content/applications/phpcatalog/
http://www.terraserver.de/terraserver.php3
http://www.ecommerceshoppingcartsoftware.org/
http://open.appideas.com/MyCart/
http://cosmicphp.com/freescripts_cosmicshoppingcart.php
http://www.affcommerce.com/
http://developer.berlios.de/projects/oos/
http://www.soft4e.com/loadshop.html
https://sourceforge.net/project/showfiles.php?group_id=83355&release_id=166221
http://scripts.justwilliams.com/amazon/index.htm

And more can be found via google and php.resourceindex.com

/vjl/

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: splitting CSV rows into multiple SQL inserts?

2005-06-22 Thread Vince LaMonica
On Wed, 22 Jun 2005, Ben Duffy wrote:

} I would read in the CSV file, and populate  two arrays, using the
} ordernumber as a key in the header array, loop through the header array
} containg $o_num, $date, $name, $addr, to do the db inserts.

Ok, I think I get this, though I am confused about doing the inserts - I 
don't want duplicate rows to be inserted into the header table. Eg:

 1116,6/22/2005,Jim Smith,44 Here St,19191980,1,CD
 1116,6/22/2005,Jim Smith,44 Here St,77736222,1,Tape

The two rows from the CSV above produce the same row data for the header 
table:

 '1116','6/22/2005','Jim Smith','44 Here St'
 '1116','6/22/2005','Jim Smith','44 Here St'

How do I make sure that only one row is inserted? How do I detect the same 
$o_num when building the header array?

/vjl/
  

} The details table would be an array of arrays, key would be ordernumber
} again, then the sub array would be the line number. You can set to 1, then
} increment until you detect a new ordernumber The contents of the detail sub
} array contains  $item_num, $quan, $desc. Loop through this this array to
} produce your details table inserts.
} 
} Ben.
} 
} 
} 
} "Vince LaMonica" <[EMAIL PROTECTED]> wrote in message
} news:[EMAIL PROTECTED]
} > On Wed, 22 Jun 2005, Sergey wrote:
} >
} > } You can insert file data in DB first, using LOAD DATA INTO FILE, after
} it'll
} > } be easy to manipulate this DB table with a help of php-script.
} >
} > Actually, I can't, as the CSV contains fields for two different tables. I
} > may have explained it better here:
} >
} > I have a CVS file that has order header *and* line item info on each line,
} > like:
} >
} > 1110,6/20/2005,Jan Doe,123 Main St,,1,Book
} > 1116,6/22/2005,Jim Smith,44 Here St,19191980,1,CD
} > 1116,6/22/2005,Jim Smith,44 Here St,77736222,1,Tape
} >
} > The above is actually two orders - one with one line item, and the 2nd
} > with two line items. I need to insert data from those lines into two
} > tables:
} >
} > insert into order_header (o_num, date, name, addr)
} > values ('1110','6/20/2005','Jan Doe','123 Main St'),
} >('1116','6/22/2005','Jim Smith','44 Here St');
} >
} > insert into line_items (o_num, item_num, quan, desc, line_order)
} > values ('1110','','1','Book','1'),
} >('1116','19191980','1','CD','1'),
} >('1116','77736222','1','Tape','2');
} >
} > Note the line_order field - it needs to increment per order for each line
} > item added to the line_items table. To complicate matters a bit, I'm
} > actually massaging the data before inserting [eg: splitting the name field
} > from the CSV into two fields for the mysql db, formatting the date field
} > for mysql, etc].
} >
} > I'm currently doing this process via a form where a user uploads the CVS
} > file [created with Excel, complete with the first row being made up the
} > Excel table's header].
} >
} > I currently do something like this:
} >
} > $fp = fopen("/tmp/"."$txt_file", "r");
} >  while ($line = fgets($fp,1024))
} >   {
} >   $i++
} >   if ($i > 1) { // skip excel header row
} > list ($o_num, $date, $name, $addr, $item_num, $quan, $desc) =
} csv_explode($line);
} > // i can now print the vars, but i get duplicate header records when
} > // there are multiple line items for a particular order. also, i
} > // need to generate the line_order field for insertion into the
} > // line_items table
} > }
} >   }
} >
} > If I try and do any processing up where my comments are, well, the
} > comments tell you what happen. I know I am reading this file line by line,
} > so I can't compare order numbers [o_num] to group multiple line item
} > orders together. So how do I go about doing that? Read the entire CSV into
} > an array? How can that help? Any tips would be most appreciated!
} >
} > Thanks!
} >
} > /vjl/
} >
} > p/s - FYI, cvs_explode() is:
} >
} > function csv_explode($str, $delim = ',', $qual = "\"")
} > {
} > $len = strlen($str);
} > $inside = false;
} > $word = '';
} > for ($i = 0; $i < $len; ++$i) {
} > if ($str[$i]==$delim && !$inside) {
} > $out[] = $word;
} > $word = '';
} > } else if ($inside && $str[

Re: [PHP] Re: splitting CSV rows into multiple SQL inserts?

2005-06-22 Thread Vince LaMonica
On Wed, 22 Jun 2005, Sergey wrote:

} You can insert file data in DB first, using LOAD DATA INTO FILE, after it'll 
} be easy to manipulate this DB table with a help of php-script.

Actually, I can't, as the CSV contains fields for two different tables. I 
may have explained it better here:

I have a CVS file that has order header *and* line item info on each line, 
like:

1110,6/20/2005,Jan Doe,123 Main St,,1,Book
1116,6/22/2005,Jim Smith,44 Here St,19191980,1,CD
1116,6/22/2005,Jim Smith,44 Here St,77736222,1,Tape

The above is actually two orders - one with one line item, and the 2nd 
with two line items. I need to insert data from those lines into two 
tables:

insert into order_header (o_num, date, name, addr)
values ('1110','6/20/2005','Jan Doe','123 Main St'),
   ('1116','6/22/2005','Jim Smith','44 Here St');

insert into line_items (o_num, item_num, quan, desc, line_order)
values ('1110','','1','Book','1'),
   ('1116','19191980','1','CD','1'),
   ('1116','77736222','1','Tape','2');

Note the line_order field - it needs to increment per order for each line 
item added to the line_items table. To complicate matters a bit, I'm 
actually massaging the data before inserting [eg: splitting the name field 
from the CSV into two fields for the mysql db, formatting the date field 
for mysql, etc].

I'm currently doing this process via a form where a user uploads the CVS 
file [created with Excel, complete with the first row being made up the 
Excel table's header]. 

I currently do something like this:

$fp = fopen("/tmp/"."$txt_file", "r");
 while ($line = fgets($fp,1024))
  {
  $i++
  if ($i > 1) { // skip excel header row
list ($o_num, $date, $name, $addr, $item_num, $quan, $desc) = 
csv_explode($line);
// i can now print the vars, but i get duplicate header records when
// there are multiple line items for a particular order. also, i 
// need to generate the line_order field for insertion into the 
// line_items table
}
  }

If I try and do any processing up where my comments are, well, the 
comments tell you what happen. I know I am reading this file line by line, 
so I can't compare order numbers [o_num] to group multiple line item 
orders together. So how do I go about doing that? Read the entire CSV into 
an array? How can that help? Any tips would be most appreciated!

Thanks!

/vjl/

p/s - FYI, cvs_explode() is:

function csv_explode($str, $delim = ',', $qual = "\"") 
{ 
$len = strlen($str); 
$inside = false; 
$word = ''; 
for ($i = 0; $i < $len; ++$i) { 
if ($str[$i]==$delim && !$inside) { 
$out[] = $word; 
$word = ''; 
} else if ($inside && $str[$i]==$qual && ($i<$len && 
$str[$i+1]==$qual)) { 
$word .= $qual; 
++$i; 
} else if ($str[$i] == $qual) { 
$inside = !$inside; 
} else { 
$word .= $str[$i]; 
} 
} 
$out[] = $word; 
return $out; 
} 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] splitting CSV rows into multiple SQL inserts?

2005-06-21 Thread Vince LaMonica
I sent this note off to the php-db list last night, but the more I thought 
about it, the more I figured this was a general looping question rather 
than a mysql-specific one.


I am attempting to take a CSV file that has order header and line item data on 
each line and split it into mulitple insert queries into a mysql db. Each line 
in the CSV file may only be one order, though it is common for there to be more 
than one item ordered, so I need to be able to loop to insert the line item 
values into the proper line item table. I also need to build a counter for a 
value that is not provided in the CVS for each line item.


Here is a sample of a few lines of the CSV:

1110,6/20/2005,Jan Doe,1234 Spring St.,Anytown,PA,17033,0618456990,22.50,1,The 
Sample Book
1114,6/22/2005,Jon Smith,888 Main St.,Big 
City,CA,92648,009444,19.95,1,Coloring Book
1114,6/22/2005,Jon Smith,888 Main St.,Big 
City,CA,92648,9834119933,4.40,1,Picture Book
1114,6/22/2005,Jon Smith,888 Main St.,Big 
City,CA,92648,948922,59.99,4,Coffee Book

In the above file, the last 4 fields [item_num, cost, quantity, title] 
belong in a line_items table. The first number, the order_number, also 
goes into the line_items table, as well as the order_header table. The 
contact info for each customer also goes into the order_header table. I do 
not want duplicate entries in the order_header table, so I can't just to a 
simple loop through each line in the text file and do an insert. I need to 
be able to group an order by the order_number [the 1st field] and insert 
the correct number of rows in both tables. I also need to create a counter 
per order showing which line item number each item is. Eg: the Coloring 
Book would be assigned a 1, the Picture book a 2, and the Coffee Book a 3 
for order #1114. The Sample Book in order #1110 would be given a 1, since 
it is the first [and only] item in that order.


I have been successful in assigning each value to a varable and looping through 
the file via:


while ($line = fgets($fp,1024))
 {
  $i++;
  if ($i > 1) { // using 1 because CSV includes a header row
 list($order_number, ...) = csv_explode($line);

[i am using an Excel generated CSV with double quotes around each value and so 
i have a csv_explode function setup to properly extract each value; also the 
real CSV has about 2 dozen fields - i just cut it down to its basics for the 
example here]


Doing 2 inserts here and closing the loop is obviously not the answer, 
since I get duplicate header rows, and I haven't built a counter for the 
line_item's table's line counter field. The primary key in the line item 
table is a combo of the order_number and the line_counter. Each fresh 
order_number needs to reset the line_counter to 1, until all line items 
for that order are inserted.


I am having difficulty figuring out how to loop through the CSV to do the 
inserts and create a line item counter. Any tips?


TIA,

/vjl/

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] readfile() and 401 pages

2004-01-16 Thread Vince LaMonica
Hi all,

I'm attempting to use readfile() to redirect the user to a .htaccess
protected page:

https://www.foo.edu/cgi-bin/stats/awstats?config=more.foo.here";);
?>

The stats/ directory is .htaccess'ed. [and the URL is even longer, with a
lot of other options tagged onto the awstats call]. I would like to be
able to redirect users to a simplier URL:

https://www.foo.edu/stats/site

and have the 'authorization required' browser dialog box pop up when going
there [like it does when they visit the long/normal URL].

Instead, what I'm getting back is a PHP error stating that HTTP/1.1
Authorization Required in line 2 of the above page. Does readfile() not
pass along 401s to the browser? I know I can do an alias in apache's
setup, which is what I plan on doing if readfile() can't be made to work.
But I am curious if this is a limitation or design in readfile().

TIA,

/vjl/

-- 
Vince LaMonica   UC Irvine,  School  of  Social Ecology
 W3 Developer   <*>  116 Social Ecology I, Irvine, CA 92697
 [EMAIL PROTECTED]  http://www.seweb.uci.edu/techsupport

 Information wants to be free.
Rent wants to be paid.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] using fwrite to create PHP files

2003-09-05 Thread Vince LaMonica
Hi all,

I wish to use fwrite() to create a small PHP file. So far, when I attempt
to do this, php parses the contents of the file that fwrite needs to
create. Eg, I have this:

$new_id = mysql_insert_id();
// create brand new file
$new_file = fopen("/var/www/html/$sitename/$submitted_url", "w");
$new_file_content = "\n"
." http://www.foo.bar/${'sitename'}.display?${'sitename'}id=$new_id&preview=y\");
 \n"
." } else { \n"
." readfile(\"http://www.foo.bar/${'sitename'}.display?${'sitename'}id=$new_id\"); \n"
." } \n"
." ?>";

write($new_file, $new_file_content);
fclose($new_file);

Note that $sitename is defined earlier in the script.

I know that $new_id and $sitename get expanded, as I tried this:

$new_file_content = "hello world. Look at my ${'sitename'}.display and my $new_id";

and the new file was created with the above text and the two vars
expanded. My problem lies in the fact that I need to put "  116 Social Ecology I, Irvine, CA 92697
 [EMAIL PROTECTED]  http://www.seweb.uci.edu/techsupport

 Tower: "Delta Zulu Romeo, turn right now and report your heading."
 Pilot: "Wilco. 341, 342, 343, 344, 345..."

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] problem matching multiple times

2003-07-18 Thread Vince LaMonica
On Fri, 18 Jul 2003, Curt Zirzow wrote:

} > Do you mean: 
} > 
} > $patterns[3] = "/###Image($count+1)###/";
} > $replacements[3] = "$sel_image = "SELECT * from ppd_photos where ppd_id = '$_GET[ppdid]' AND  
place_holder = '$thephoto[0]'";

} What does this return?
} 
} I'm a bit confused right now..

The query simply returns one row with all the htmlstuff [width, height, 
caption, image_holder, etc] for one image. In otherwords, $message might 
contain:
   
 
-
Hello world, look at my [b]cat[/b]: ###Image1### Nice, huh?
And now look at my [b]dog[/b]: ###Image2### Not so nice, eh?
-

I'm using a big preg_replace call to replace any of that custom formatting 
tag [eg: [b][/b]] as well as the ###ImageX### tags. Instead of replacing 
###Image1### with some formatting code, I need to look up ###Image1### in 
the database, which stores the formatting codes. So the in the above 
query, $thephoto[0] contains '###Image1###', since it is the first photo 
on the page. However, when preg_replace finds a 2nd photo, with a 
image_holder of ###Image2###, the select statement is still run against 
the first image place holder, ###Image1###. So I need to advance the 
counter before running the SQL statement

If I leave out the sql stuff and do something like this:

$patterns[3] = "/###Image(\d+)###/si";
$replacements[3] = "My Photograph\$1";

Then the page sucessfully substitutes "My Photograph1" for every place 
that $message contained ###Image1### and "My Photograph2" for every place 
that $message contained ###Image2###. 

So I need to somehow run preg_match on that part of $message in order to 
extract ###Image1###, ###Image2###, ###Image3###, etc from the message and 
look them up in the database. I think. :-\

} after the user enters in his stuff, he wants, in your CMS and before you
} save it, parse it for all the special tags you have and keep track of it
} somewhere.  That way when you output it (in this script) you only need
} to apply the necessary pattern/replacements before outputing it to the
} browser.  

Good idea! Thanks very much!

Thanks again for your help, and time, with this. I do appreciate it.

/vjl/

-- 
Vince LaMonica   UC Irvine,  School  of  Social Ecology
 W3 Developer   <*>  116 Social Ecology I, Irvine, CA 92697
 [EMAIL PROTECTED]  http://www.seweb.uci.edu/techsupport

Linux price to performance ratio: Error: Divide by zero. Continue?(Y/N)

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Using href as a submit for a form

2003-07-18 Thread Vince LaMonica
On Fri, 18 Jul 2003, Ron Allen wrote:

} I am using a form to submit to mysql.  What I would like to do is to use a
} link to submit the form instead of the standard submit button.  Help is
} appreicated.

You could use a simple GET to submit the form. Make sure you have 
register_globals off though!

Something like this:

https://www.mysite.org/submit_form.php?user=me&client=bsd&browser=galeon

The page that calls the above page would have to have form entities for 
the 3 fields.

Then, on the submit_form page, you would take those vars and insert them 
in the database:

$insert_user = $_GET["user"];
$insert_client = $_GET["client"];
$insert_browser = $_GET["browser"];

Obviously the user could easily change the values in the URL before they 
submit [if they look at the html code behind the page]. Like all form 
processing, you need to make sure that the values submitted by the user 
are valid. register_globals being off is a step, but there are a lot of 
error correction functions you should run before submitting form data into 
a db.

HTH,

/vjl/


-- 
Vince LaMonica   UC Irvine,  School  of  Social Ecology
 W3 Developer   <*>  116 Social Ecology I, Irvine, CA 92697
 [EMAIL PROTECTED]  http://www.seweb.uci.edu/techsupport

"This is like losing a game by forfeit when your team was ahead
with the bases loaded and your best batter on deck." 
 - Rep. John Conyers, on the DOJ agreeing to settle with Microsoft

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] problem matching multiple times

2003-07-18 Thread Vince LaMonica
On Fri, 18 Jul 2003, Curt Zirzow wrote:

} btw, you know you can do this in one step:
} 
} $message = preg_replace("/\[(i|b)\](.*?)\[\/(i|b)\]/si", "<\$1>\$2", $message);

Doh! Thanks for the tip...that'll save some lines of code :)

} > $patterns[3] = "#\#\#\#Image(.*?)\#\#\##si"; 
} > // this matches just fine strings like ###Image1### and ###Image2###
} 
} I would change mabey make sure you catching a digit and the serpator for
} readabilty /###Image(\d+)###/si

Ok. Changed it and you're right - much easier to understand what the 
patern is being searched.

} > [...] 
} >  if ($_GET[ppdid] != "") { // the ppdid var is passed in the URL 
} >  $sel_image = "SELECT * from ppd_photos where ppd_id = '$_GET[ppdid]' AND 
place_holder = '$thephoto[0]'";
} > // in this case, the page with a ppdid of '3' has 2 images, who's 
} > // placeholders are: ###Image1### and ###Image2###
} >  $sel_image_result = safe_query($sel_image);
} >  $sel_image_row = mysql_fetch_array($sel_image_result);
} >  $image_id = $sel_image_row["image_id"];
} >  $image_name = $sel_image_row["image_name"];
} >  $caption = $sel_image_row["caption"];
} >  $width = $sel_image_row["width"];
} >  $height = $sel_image_row["height"];
} >  $image_alignment = $sel_image_row["image_alignment"];
} >  $replacements[3] = "  116 Social Ecology I, Irvine, CA 92697
 [EMAIL PROTECTED]  http://www.seweb.uci.edu/techsupport

 Your mouse has moved. Windows NT must be restarted for the
 change to take effect. Reboot now? [ OK ]

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP] problem matching multiple times

2003-07-17 Thread Vince LaMonica
Hi All,

I have a content management system that I'm building and I'm having issues 
matching a variable that needs to be replaced with rows from a database. 
Basicly I have something setup similar to bbcode, where a user enters 
html-like text for formatting - eg: [b]bold text[/b]. I'm now adding the 
ability to link photos in this formatted text. 

In order to display the page using html, I obviously need to convert the 
special tags to their real ones. With the images, I'm actually pulling 
data [image name, width, height, image_placer, alignment, etc] from a 
database. There can be more than 1 image on a page [and more than 10, 
actually]. The user would simply type into the CMS editor something like, 
"Here is a photo of my dog ###Image1###" The ###Image1### is a 
placeholder. The user gets assigned a placeholder for each image they 
upload. They then assign different parameters to that image [a caption, 
and center/left/right alignment].

In order to display this data, I call a function called vencode() on the 
page that a user will see:



The entire page's content section is inside $message. The vencode() 
function looks like this:

function vjencode($message) {
 
 $message = " " . $message ;

##--- [b] and [/b] for bolding text.
 $message = preg_replace("/\[b\](.*?)\[\/b\]/si", "\\1", $message);

##--- [i] and [/i] for italicizing text.
 $message = preg_replace("/\[i\](.*?)\[\/i\]/si", "\\1", $message);


##--- Patterns and replacements for URL and email tags..   
$patterns = array();
$replacements = array();

##--- [url]://www.seweb.uci.edu[/url] code..
$patterns[0] = "#\[url\]([a-z]+?://){1}(.*?)\[/url\]#si";
$replacements[0] = '\1\2';


##--- [url]www.seweb.uci.edu[/url] code.. (no :// prefix).
$patterns[1] = "#\[url\](.*?)\[/url\]#si";
$replacements[1] = 'http://\1";>\1';

##--- [url=://www.seweb.uci.edu]Social Ecology Home[/url] code..
$patterns[2] = "#\[url=([a-z]+?://){1}(.*?)\](.*?)\[/url\]#si";
$replacements[2] = '\3';

##--- display photos [having problems with this]
$patterns[3] = "#\#\#\#Image(.*?)\#\#\##si"; 
// this matches just fine strings like ###Image1### and ###Image2###


 if ($_GET[ppdid] != "") { // the ppdid var is passed in the URL 
 $sel_image = "SELECT * from ppd_photos where ppd_id = '$_GET[ppdid]' AND place_holder 
= '$thephoto[0]'";
// in this case, the page with a ppdid of '3' has 2 images, who's 
// placeholders are: ###Image1### and ###Image2###
 $sel_image_result = safe_query($sel_image);
 $sel_image_row = mysql_fetch_array($sel_image_result);
 $image_id = $sel_image_row["image_id"];
 $image_name = $sel_image_row["image_name"];
 $caption = $sel_image_row["caption"];
 $width = $sel_image_row["width"];
 $height = $sel_image_row["height"];
 $image_alignment = $sel_image_row["image_alignment"];
// replacements[3] is all one one line -sorry about word wrap!
 $replacements[3] = "$caption";
}

$message = preg_replace($patterns, $replacements, $message);

return $message;
} //end of function

In the case of the page with the ppdid of '3', there are two images 
assigned to that page. However, when running the above code, I two photos 
of the first listed image! Eg, the text in $message looks like this:

-
Hello world, look at my [b]cat[/b]: ###Image1### Nice, huh?
And now look at my [b]dog[/b]: ###Image2### Not so nice, eh?
-

The substitution code also translates linebreaks as s and such, but I 
didn't think I needed to include the entire list of substitutions it 
makes. 

I'm sure I need a while loop in there somewhere, but I can not figure out 
where. I know the code is  looping through the other substitutions ok, 
since all text that should be bold is, and all links that need to be made 
into valid URIs are. 

The db query does run fine if running within mysql, and substituting 
###Image1### and ###Image2### for $thephoto[0]. I know that $thephoto[1] 
simply contains a "1" [since that is the value of $patterns[3]].

Any tips about where I need to loop and how, would be most appreciated! 

/vjl/

-- 
Vince LaMonica   UC Irvine,  School  of  Social Ecology
 W3 Developer   <*>  116 Social Ecology I, Irvine, CA 92697
 [EMAIL PROTECTED]  http://www.seweb.uci.edu/techsupport

 If it be now, 'tis not to come; if it be not to come, it will be now;
 if it be not now, yet it will come: the readiness is all." 
   -- William Shakespeare, "Hamlet." 

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



Re: [PHP] Re: verify file types when uploading to server...

2002-04-18 Thread Vince LaMonica

On Thu, 18 Apr 2002, Miguel Cruz wrote:

} Not sure what you're tring to achieve, but that only checks the file's
} name. You might want to use file (man 1 file) to verify that it actually
} is a JPEG, since people can put malicious data into a file named xxx.jpg
} and perhaps fool IE into doing bad things.

Another idea:

$the_file_type = $HTTP_POST_FILES['filename']['type'];

$registered_types = array(
"image/gif" => ".gif",
"image/pjpeg"=> ".jpg, .jpeg",
"image/jpeg"=> ".jpg, .jpeg",
"application/msword"=> ".doc",
"application/vnd.ms-excel"=> ".xls",
"application/octet-stream"=> ".exe, .fla",
"application/pdf" => ".pdf"
);

$allowed_images = array("image/gif","image/pjpeg","image/jpeg");

 if (!in_array($the_file_type,$allowed_images))
 {
 // produce your error text here
 }

This looks at the mimetype of the file, using the
$HTTP_POST_FILES['filename']['type'] varible [note that "filename" is the
name passed from your form - "type" is the actual string you need to use
to access the mimetype.

Read http://us.php.net/manual/en/features.file-upload.php for more info on
this.

HTH,

/vjl/

-- 
Vince LaMonica   UC Irvine,  School  of  Social Ecology
 W3 Developer   <*>  116 Social Ecology I, Irvine, CA 92697
 [EMAIL PROTECTED] https://www.seweb.uci.edu/~vjl

If Bill Gates had a nickel for every time Windows crashed...
  ... oh wait, never mind.


-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php




[PHP] HTTP_POST_FILES and Mozilla 0.9.9

2002-04-17 Thread Vince LaMonica

Hi all,

I'm having a difficult time determining if this is a Mozilla .99 bug, or
something in PHP [currently using 4.0.6 under linux 2.4.8]. Using 2 small
test files:

## upload1.html ##

upload test

 






## upload2.php ##



With Mozilla .9.4.1 [eg: Netscape 6.2.2 for windoze], Netscape 4.79, Opera
6.0.1, and IE 5.5sp2, if a user hits the submit button *without*
uploading, the proper string ["nothing was uploaded"] is returned.
However, if a user has Galeon v1.2.0 or Mozilla 0.9.9 [running under
linux], the "a file was uploaded" string will appears since
$HTTP_POST_FILES['incoming']['tmp_name'] is an empty string. From reading
the PHP docs, if no file was uploaded, 'tmp_name' should be "none", which
it is if you're using a non-Mozilla .99 based browser.

If a user does upload a file, all browsers are happy ['tmp_name' is
assigned properly].

Is this a browser/gecko bug, or a PHP bug?

TIA,

/vjl/ [who noticed bugs #11198, 10602, 16426 and 13863, but all are
closed]

-- 
Vince LaMonica   UC Irvine,  School  of  Social Ecology
 W3 Developer   <*>  116 Social Ecology I, Irvine, CA 92697
 [EMAIL PROTECTED] https://www.seweb.uci.edu/~vjl

   Life is what happens to you when you're making other plans.
 - Betty Talmadge



-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php