SitePoint Sponsor |
|
User Tag List
Results 1 to 25 of 55
-
Nov 28, 2006, 11:36 #1
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Using getimagesize with an ARRAY? Need help please.
I used this getimagesize on anothr page on my site and it works fine. On the first page I used it on the user can upload only one image. I am trying to use it on another page now. On this page of the site it is a profile page. The user can upload up to six pictures when they first create thier profile. If the user doesn't upload all six photos and only uploads only three when they then choose to edit thier profile the three photos they previously uploaded are lined side by side with the other three not uploaded file inputs under it. I think the getimagesize is not working because it is more than one image. With the new pictures the code pulls the original pictures the user uploaded ($_POST['OldImages']) I think this is why I might be getting an error. I am not sure. I did use rtrim for an ARRAY but it doesn't seemt o be working. I will include my code and my error. when I try to upload a pic I get an error of:
Warning: getimagesize: Unable to open 'Array' for reading. in c:\apache\htdocs\ds\edit.php on line 8
Here is line 8:
$imgSize = getimagesize(rtrim($_FILES['images']['tmp_name']));
Then if I click the back button on my browser the pic was uploaded but not passed thru making sure it is only .gif or .jpg or that the max width and height is 640! Any help would be greatly appreciated.
Here is the whole bunch of code:
PHP Code:if(isset($_POST[s1]))
{
$imgSize = getimagesize(rtrim($_FILES['images']['tmp_name']));
if($imgSize === false)
{
//not an image
$error = "<b>Your banner must be an image</b>";
}
else if ($imgSize[0] = 640 || $imgSize[1] = 640)
{
$error = "<b>For best results your image should be either 640 wide by 480 high<br>
or 480 wide by 640 high, no larger!</b>";
}
else if($imgSize[2] != 1 && $imgSize[2] != 2)
{
$error = "<b>You can upload only .gif & .jpg image files!</b>";
}
if(!empty($_FILES['images']['name'][0]))
{
while(list($key,$value) = each($_FILES['images']['name']))
{
if(!empty($value))
{
$NewImageName = $t."_offer_".$value;
copy($_FILES['images']['tmp_name'][$key], "ds_images/".$NewImageName);
$MyImages[] = $NewImageName;
}
}
if(!empty($MyImages))
{
$ImageStr = implode("|", $MyImages);
if(!empty($_POST['OldImages']))
{
$ImageStr = $ImageStr."|".$_POST['OldImages'];
}
}
}
else
{
$ImageStr = $_POST['OldImages'];
}
$catInfo = explode("|", $_POST[SelectCategory]);
$CategoryID = $catInfo[0];
$SubcategoryID = $catInfo[1];
$SubcategoryName = $catInfo[2];
-
Nov 28, 2006, 12:09 #2
- Join Date
- Jul 2006
- Location
- Kansas City, MO
- Posts
- 280
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
$imgSize = getimagesize(rtrim($_FILES['images']['tmp_name']));
Okay rtrim is completely inappropriate here.
You need to figure out the imagesize for each image anyway. Where is your loop? You need something like...
PHP Code:foreach($_FILES['images']['tmp_name'] as $tmpImageName) {
$imgSize = getimagesize($tmpImageName);
// Test for dimensions and filetype...
}
-
Nov 28, 2006, 12:42 #3
This:
Originally Posted by netfreakz
PHP Code:else if ($imgSize[0] <= 640 || $imgSize[1] <= 640)
-
Nov 28, 2006, 12:57 #4
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by ZareMedia
ok i put your code into my script replacing the original getimagesize i post and i got these errors...
Warning: getimagesize: Unable to open 'none' for reading. in c:\apache\htdocs\ds\edit.php on line 9
Warning: getimagesize: Unable to open 'none' for reading. in c:\apache\htdocs\ds\edit.php on line 9
-
Nov 28, 2006, 12:58 #5
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by logic_earth
-
Nov 28, 2006, 13:21 #6
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok the script is getting the new image name if a new image is being uploaded but also posting the old images the user might have uploaded previously. Wouldn't i also have to pass the $_POST[OldImages] thru getimagesize too for the script to work on my page? If so would I be able to configure getimagesize like this:
foreach($_FILES['images']['tmp_name'], $_POST['OldImages'] as $tmpImageName) {
$imgSize = getimagesize($tmpImageName);
// Test for dimensions and filetype...
}
-
Nov 28, 2006, 19:49 #7
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Does anyone have any idea what I am doing wrong I still have no luck....
-
Nov 28, 2006, 19:53 #8
- Join Date
- Jul 2006
- Location
- Kansas City, MO
- Posts
- 280
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
PHP Code:foreach($_FILES['images']['tmp_name'] as $tmpImageName) {
if (file_exists($tmpImageName)) {
$imgSize = getimagesize($tmpImageName);
// Test for dimensions and filetype...
}
}
-
Nov 28, 2006, 20:00 #9
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by ZareMedia
-
Nov 28, 2006, 20:03 #10
- Join Date
- Jul 2006
- Location
- Kansas City, MO
- Posts
- 280
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Paste your code. Your sloppy coding has numerous problems up above, so I won't be surprised to point out a handful of more errors.
-
Nov 28, 2006, 20:08 #11
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by ZareMedia
CODE:
PHP Code:<?
require_once("conn.php");
require_once("includes.php");
if(isset($_POST[s1]))
{
foreach($_FILES['images']['tmp_name'] as $tmpImageName) {
if (file_exists($tmpImageName)) {
$imgSize = getimagesize($tmpImageName);
// Test for dimensions and filetype...
}
}
if($imgSize === false)
{
//not an image
$error = "<b>Your picture must be an image</b>";
}
else if ($imgSize[0] <= 640 || $imgSize[1] <= 640)
{
$error = "<b>For best results your image should be either 640 wide by 480 high<br>
or 480 wide by 640 high, no larger!</b>";
}
else if($imgSize[2] != 1 && $imgSize[2] != 2)
{
$error = "<b>You can upload only .gif & .jpg image files!</b>";
}
if(!empty($_FILES['images']['name'][0]))
{
while(list($key,$value) = each($_FILES['images']['name']))
{
if(!empty($value))
{
$NewImageName = $t."_offer_".$value;
copy($_FILES['images']['tmp_name'][$key], "ds_images/".$NewImageName);
$MyImages[] = $NewImageName;
}
}
if(!empty($MyImages))
{
$ImageStr = implode("|", $MyImages);
if(!empty($_POST[OldImages]))
{
$ImageStr = $ImageStr."|".$_POST[OldImages];
}
}
}
else
{
$ImageStr = $_POST[OldImages];
}
$catInfo = explode("|", $_POST[SelectCategory]);
$CategoryID = $catInfo[0];
$SubcategoryID = $catInfo[1];
$SubcategoryName = $catInfo[2];
$q1 = "UPDATE ds_profile set
-
Nov 28, 2006, 20:59 #12PHP Code:
<?php
require_once("conn.php");
require_once("includes.php");
$acceptedImages = array(IMG_GIF, IMG_JPG, IMG_PNG);
if(isset($_POST[s1])) {
foreach($_FILES['images']['tmp_name'] as $tmpImageName) {
if (file_exists($tmpImageName)) {
$imgSize = getimagesize($tmpImageName);
if ($imgSize === false) {
exit('<b>Your picture must be an image.</b>');
} else if ($imgSize[0] > 640 || $imgSize[1] > 640) {
exit('<b>Your image can not be larger then 640 by 640.</b>');
} else if (!in_array($imgSize[2], $acceptedImages)) {
exit('<b>You can only upload GIF, JPEG, and PNGs files.</b>');
}
}
}
$l = count($_FILES['images']['tmp_name']);
for ($i = 0; $i < $l; $i++) {
// Okay...I'm really confused at what you are exactly doing... but to
// Process the uploaded images you would do it here...in this for loop.
// That is if i assume what you want but like I said very confusing.
}
}
-
Nov 28, 2006, 21:12 #13
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by logic_earth
-
Nov 28, 2006, 21:26 #14
Well i'll try it on my end and server if it work or requires changing i'll post the results.
-
Nov 28, 2006, 21:27 #15
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by logic_earth
-
Nov 28, 2006, 23:35 #16
- Join Date
- Sep 2006
- Location
- Fairbanks, AK
- Posts
- 1,621
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
netfreakz, it looks like you're again back to one of the problems we solved last week, specifically that IMG_GIF, IMG_JPG, and now IMG_PNG are not defined. Either define these (with define) or replace them with the numerical values noted in the PHP manual for getimagesize for the image types you want to allow.
-
Nov 28, 2006, 23:38 #17
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kromey
Ok The script i will post here take a look I will have to explain what it is doing so you understand. Other people were getting confused. Please give me a few minutes to prepare this new post for your to read.
-
Nov 28, 2006, 23:48 #18
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Ok a user can go to my website and register, Once they register it takes them to a control panel which gives them an option to set a profile where they can type stuff about things and also upload up to six images. If the first time they make thier profile they only upload 3 images in the future if they decide to edit thier profile they will have the option to add another three photos yet the original three the uploaded when they first made thier profile will automatically be there with the delete option under each pic. If the user does not delete the orig pics that is where the part of this script says
PHP Code:if(!empty($_POST[OldImages]))
{
$ImageStr = $ImageStr."|".$_POST[OldImages];
}
}
}
else
{
$ImageStr = $_POST[OldImages];
}
Here is the code:
PHP Code:if(isset($_POST[s1]))
{
foreach($_FILES['images']['tmp_name'] as $tmpImageName) {
if (file_exists($tmpImageName)) {
$imgSize = getimagesize($tmpImageName);
// Test for dimensions and filetype...
}
}
if($imgSize === false)
{
//not an image
$error = "<b>Your banner must be an image</b>";
}
else if ($imgSize[0] <= 640 || $imgSize[1] <= 640)
{
$error = "<b>For best results your image should be either 640 wide by 480 high<br>
or 480 wide by 640 high, no larger!</b>";
}
else if($imgSize[2] != 1 && $imgSize[2] != 2)
{
$error = "<b>You can upload only .gif & .jpg image files!</b>";
}
if(!empty($_FILES['images']['name'][0]))
{
while(list($key,$value) = each($_FILES['images']['name']))
{
if(!empty($value))
{
$NewImageName = $t."_offer_".$value;
copy($_FILES['images']['tmp_name'][$key], "re_images/".$NewImageName);
$MyImages[] = $NewImageName;
}
}
if(!empty($MyImages))
{
$ImageStr = implode("|", $MyImages);
if(!empty($_POST[OldImages]))
{
$ImageStr = $ImageStr."|".$_POST[OldImages];
}
}
}
else
{
$ImageStr = $_POST[OldImages];
}
$catInfo = explode("|", $_POST[SelectCategory]);
$CategoryID = $catInfo[0];
$SubcategoryID = $catInfo[1];
$SubcategoryName = $catInfo[2];
$q1 = "UPDATE ds_listings set
CategoryID = '$CategoryID',
SubcategoryID = '$SubcategoryID',
SubcategoryName = '$SubcategoryName',
Weight = '$_POST[Weight]',
city = '$_POST[city]',
state = '$_POST[state]',
oneliner = '$_POST[oneliner]',
greeting = '$_POST[greeting]',
description1 = '$_POST[description1]',
Price = '$_POST[Price]',
incall = '$_POST[incall]',
description2 = '$_POST[description2]',
Height = '$_POST[Height]',
BodyType = '$_POST[BodyType]',
Liner = '$_POST[Liner]',
HairColor = '$_POST[HairColor]',
EyeColor = '$_POST[EyeColor]',
Ethnicity = '$_POST[Ethnicity]',
UserAge = '$_POST[UserAge]',
AttentionColor = '$_POST[AttentionColor]',
DetailsColor = '$_POST[DetailsColor]',
Preference = '$_POST[Preference]',
Site = '$_POST[Site]',
Website = '$_POST[Website]',
Visit = '$_POST[Visit]',
FromMonth = '$_POST[FromMonth]',
FromDay = '$_POST[FromDay]',
ToMonth = '$_POST[ToMonth]',
ToDay = '$_POST[ToDay]',
image = '$ImageStr'
where ListingID = '$_GET[id]' and AgentID = '$_SESSION[AgentID]' ";
mysql_query($q1);
if(mysql_error())
{
echo mysql_error();
}
else
{
header("location:info.php?id=$_GET[id]");
exit();
}
}
-
Nov 28, 2006, 23:54 #19
- Join Date
- Sep 2006
- Location
- Fairbanks, AK
- Posts
- 1,621
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Okay, first thing I see right off the bat is something we went over last night, specifically that arrays indexed non-numerically (i.e. associative arrays) use strings as keys; thus, things like
PHP Code:if(!empty($_POST[OldImages]))
PHP Code:if(!empty($_POST['OldImages']))
Next, take a look at the code that Logic_Earth posted above, and notice that in his code image validation happens inside the foreach loop. That's where it needs to be, otherwise you're only validating the last image (if even that).
Make those changes and repost your code along with any/all errors and we'll see where we need to go from there.
-
Nov 28, 2006, 23:54 #20
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
would this work?
PHP Code:foreach($_FILES['images']['tmp_name'], $_POST['OldImages'] as $tmpImageName) {
$imgSize = getimagesize($tmpImageName);
// Test for dimensions and filetype...
}
-
Nov 28, 2006, 23:55 #21
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kromey
-
Nov 28, 2006, 23:56 #22
-
Nov 28, 2006, 23:57 #23
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
oh ok
-
Nov 28, 2006, 23:57 #24
-
Nov 28, 2006, 23:58 #25
- Join Date
- Jan 2006
- Posts
- 221
- Mentioned
- 0 Post(s)
- Tagged
- 0 Thread(s)
Originally Posted by kromey
i will post it in a minute
Bookmarks