Markie
Posts: 251
|
| Posted: 10/30/2008, 8:21 AM |
|
Based on PHP's GetImageSize I try to store the height and with of an uploaded image in my database. Until now, I don't do well.
This is my AfterProcessFile code:
$tmpName=$uploaded1->FileUpload1->GetValue();
list($width, $height, $type, $attr) = getimagesize($tmpName);
$Component->UploadImageSize->Value = $tmpName;
As you can see, I have a (hidden) field named UploadImageSize. This hidden field is connected to the specific database field.
Unfortunately, my code doesn't work very well, as this is what my webbrowser tells me:
###
Warning: getimagesize(200810301616190.2008-10-20_152155.jpg) [function.getimagesize]: failed to open stream: No such file or directory in C:\xampp\htdocs\newproject\NewPage1_events.php on line 23
Warning: Cannot modify header information - headers already sent by (output started at C:\xampp\htdocs\newproject\NewPage1_events.php:23) in C:\xampp\htdocs\newproject\NewPage1.php on line 862
###
I realize my code contains errors, but it's the best I could do until this point. I hope somebody will help me to complete my quest.
M@rkie
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
melvyn
Posts: 333
|
| Posted: 10/30/2008, 8:51 AM |
|
With this error 1 will never work:
Change this:
$Component->UploadImageSize->Value = $tmpName;
For this:
$Component->UploadImageSize->SetValue($tmpName);
Now, let's go to getimagesize:
Your image field is FileUpload1, I don't know the folder, you need it. Let's say the upload folder is ../images/samples/
You need to do this
$filename = "../images/samples/".$uploaded1->FileUpload1->GetValue();
list($width, $height) = getimagesize($filename); // Get new dimensions
// the following lines are only to debug, let's see the result in screen. after get them working delete them
echo "<br > width: ".$width;
echo "<br> heigth: ".$heigth;
exit(0); // stop executing, because we need to know this now.
// delete until here.
Enjoy!
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com |
 |
 |
Markie
Posts: 251
|
| Posted: 10/30/2008, 10:13 AM |
|
Thanks Melvyn, you saved my day and I've also learned something again !
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
melvyn
Posts: 333
|
| Posted: 10/30/2008, 11:54 AM |
|
You're welcome.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com |
 |
 |
Markie
Posts: 251
|
| Posted: 10/31/2008, 3:10 AM |
|
Melvyn, this is working:
$filename = "uploads/".$uploaded1->FileUpload1->GetValue();
list($width, $height) = getimagesize($filename); // Get new dimensions
echo "<br > width: ".$width;
echo "<br> heigth: ".$heigth;
exit(0);
but I don't know how to put the width and height output in my UploadImageSize field. Whatever I try with this command:
$Component->UploadImageSize->SetValue();
The error is:
Fatal error: Call to a member function SetValue() on a non-object
I want to populate field UploadImageSize with the width and height
M@rkie
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
Gena
Posts: 591
|
| Posted: 10/31/2008, 3:23 AM |
|
try this 
//End NewRecord1_BeforeInsert
//put value into your hidden field
$Component-> UploadImageSize->Value = ....;
of course you can put just one value - width or height - not both in the same field 
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 10/31/2008, 3:58 AM |
|
I think I'm getting lost in the dark now. This is what I have at the moment:
AfterProcessFile custom code (upload component):
$tmpName = "uploads/".$uploaded1->FileUpload1->GetValue();
list($width, $height) = getimagesize($filename);
BeforeInsert custom code (grid form):
$Component-> UploadImageSize->Value = $tmpName;
I hope width or height will appear in the field UploadImageSize, but nothing happens and no dimension is added to the database.
What to do ?
M@rkie
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
Gena
Posts: 591
|
| Posted: 10/31/2008, 4:07 AM |
|
Quote Markie:
I think I'm getting lost in the dark now. This is what I have at the moment:
AfterProcessFile custom code (upload component):
$tmpName = "uploads/".$uploaded1->FileUpload1->GetValue();
list($width, $height) = getimagesize($filename);
BeforeInsert custom code (grid form):
$Component-> UploadImageSize->Value = $tmpName;
I hope width or height will appear in the field UploadImageSize, but nothing happens and no dimension is added to the database.
What to do ?
Just think about :)
$tmpName - what is this?
$filename - is your image file name?
list($width, $height) = getimagesize($filename); - will returns width and height into variable $width and $height
UploadImageSize - this is ONE field in your DB and hidden field on your record?
To store TWO variables you (I assume ) you need two fields like width and height!
and aftre like this
$Component-> width ->Value = $width ;
$Component-> height->Value = $height;
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 10/31/2008, 5:07 AM |
|
$tmpName is nothing, I thought it would be helpfull to use a temporary file, but it's clearly not.
Thanks for your help. $filename is my image file name, yes. I now have this AfterProcessFile code:
$filename = "uploads/".$uploaded1->FileUpload1->GetValue();
list($width, $height) = getimagesize($filename); // Get new dimensions
$Component-> width ->Value = $width ;
$Component-> height->Value = $height;
and this BeforeInsert code in the grid:
$Component-> UploadImageSize->Value = $width;
Field UploadImageSize is connected to my database field Imagesize and I will use it to store the width.
All errors are gone now but still nothing is added to my database. Any idea ?
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
mamboBROWN
Posts: 1713
|
| Posted: 10/31/2008, 5:13 AM |
|
Markie
It appears that your issue has been resolved. If it is so, could you please put [RESOLVED] or {SOLVED] in the title of his thread. Thanks.
|
 |
 |
Markie
Posts: 251
|
| Posted: 10/31/2008, 5:20 AM |
|
Hi MamboBrown, I will certainly add [SOLVED] to this topic as soon as it is really solved. But, it's not totally solved at this point. My last question to Gena was:
I now have this AfterProcessFile code:
$filename = "uploads/".$uploaded1->FileUpload1->GetValue();
list($width, $height) = getimagesize($filename); // Get new dimensions
$Component-> width ->Value = $width ;
$Component-> height->Value = $height;
and this BeforeInsert code in the grid:
$Component-> UploadImageSize->Value = $width;
Field UploadImageSize is connected to my database field Imagesize and I will use it to store the width.
All errors are gone now but still nothing is added to my database. Any idea ?
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
Gena
Posts: 591
|
| Posted: 10/31/2008, 5:41 AM |
|
put code with getimagesize into BeforeInsert.
now you get $width in AfterProcessFile and want to use in BeforeInsert.
or declare it as global.
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 10/31/2008, 6:46 AM |
|
Allright, there is something happening in my database.
Now, I have this AfterProcessFile code:
$filename = "uploads/".$uploaded1->FileUpload1->GetValue();
and this BeforeInsert code:
list($width, $height) = getimagesize($filename); // Get new dimensions
$Component-> width ->Value = $width ;
$Component-> height->Value = $height;
$Component-> UploadImageSize->Value = width;
Now I get the literal term "width" in my MySQL database field, instead of a number like 680 etc.
If I try
$Component-> UploadImageSize->Value = $width;
nothing is added to my database field, what's the final solution ? (I feel I am soooo close now)
M@rkie
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
melvyn
Posts: 333
|
| Posted: 10/31/2008, 8:48 AM |
|
Hello Markie
Check your code to work as this:
$Component-> UploadImageSize->SetValue($width);
In this:
Quote :$Component-> UploadImageSize->Value = width;
Now I get the literal term "width" in my MySQL database field, instead of a number like 680 etc.
width, without $ is only content, not a variable.
$Component->.......->value = X I don't know if that ever work.
$Component->.......->SetValue(X) This work
Put everything in AfterProcessFile.
Melvyn
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com |
 |
 |
Gena
Posts: 591
|
| Posted: 10/31/2008, 9:37 AM |
|
post here:
- your tabel layout
- your page code (html)
and try to put echo
echo "<br > width: ".$width;
echo "<br> heigth: ".$heigth;
exit(0);
to see if you get a values...
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 10/31/2008, 10:15 AM |
|
First of all I want to mention that I am SO GLAD with your help guys ! I really want to get the imagesize and I feel like a kind of jurk that I can't achieve this.
@ Melvyn:
When I use SetValue( ...) I get this error:
Fatal error: Call to a member function SetValue() on a non-object ...
@ Gena
when I use:
echo "<br > width: ".$width;
echo "<br> heigth: ".$heigth;
it's working, I get results, but with:
$Component->ImageWidth->Value = $width;
my database field is empty
My table layout:
TABLE `uploaded` (
`id` int(11) NOT NULL auto_increment,
`Name` tinytext,
`Photo` tinytext,
`Photographer` tinytext,
`FileSize` varchar(4) default NULL,
`Basename` tinytext,
`Timestamp` datetime default NULL,
`Imagewidth` tinytext,
`Imageheight` tinytext,
PRIMARY KEY (`id`)
) ENGINE=MyISAM AUTO_INCREMENT=497 DEFAULT CHARSET=latin1;
The HTML:
<!-- BEGIN Record uploaded1 -->
<form id="uploaded1" name="{HTMLFormName}" action="{Action}" method="post" enctype="{HTMLFormEnctype}">
<h2><font color="#ff0000">{Error}</font></h2>
<table align="center">
<tr>
<td> </td>
</tr>
<!-- BEGIN Error -->
<tr>
<td></td>
</tr>
<!-- END Error -->
<tr>
<th>
<p align="left">
<!-- BEGIN FileUpload FileUpload1 --><input id="uploaded1FileUpload1ControlName" type="hidden" value="{State}" name="{ControlName}">
<!-- BEGIN Info --> {FileName} {FileSize} bytes.<!-- END Info -->
<!-- BEGIN Upload --><input id="uploaded1FileUpload1FileControl" type="file" name="{FileControl}"><!-- END Upload -->
<!-- BEGIN DeleteControl -->Delete<input id="uploaded1FileUpload1DeleteControl" type="checkbox" name="{DeleteControl}" {DeleteChecked}><!-- END DeleteControl --><!-- END FileUpload FileUpload1 --> </p>
</th>
</tr>
<tr>
<th>
<p align="left">
<select id="uploaded1Photographer" name="{Photographer_Name}">
<option value="" selected>select a photographer</option>
{Photographer_Options}
</select>
</th>
</tr>
<tr>
<th>
<p align="left"><input id="uploaded1Name1" type="hidden" value="{Name1}" name="{Name1_Name}"><input id="uploaded1Basename" type="hidden" value="{Basename}" name="{Basename_Name}"><input id="uploaded1Timestamp" type="hidden" value="{Timestamp}" name="{Timestamp_Name}"><input id="uploaded1FileSize" type="hidden" value="{FileSize}" name="{FileSize_Name}"><input id="uploaded1ImageWidth" type="hidden" value="{ImageWidth}" name="{ImageWidth_Name}"><input id="uploaded1ImageHeight" type="hidden" value="{ImageHeight}" name="{ImageHeight_Name}"></p>
</th>
</tr>
<tr>
<td align="right">
<p align="left">
<!-- BEGIN Button Button_Insert --><input id="uploaded1Button_Insert" type="image" src="Styles/None/Images/en/ButtonInsert.gif" value="Add" border="0" name="{Button_Name}"><!-- END Button Button_Insert -->
<!-- BEGIN Button Button_Update --><input id="uploaded1Button_Update" type="image" src="Styles/None/Images/en/ButtonUpdate.gif" value="Submit" border="0" name="{Button_Name}"><!-- END Button Button_Update -->
<!-- BEGIN Button Button_Delete --><input id="uploaded1Button_Delete" type="image" src="Styles/None/Images/en/ButtonDelete.gif" value="Delete" border="0" name="{Button_Name}"><!-- END Button Button_Delete -->
<!-- BEGIN Button Button_Cancel --><input id="uploaded1Button_Cancel" type="image" src="Styles/None/Images/en/ButtonCancel.gif" value="Cancel" border="0" name="{Button_Name}"><!-- END Button Button_Cancel --></p>
</td>
</tr>
</table>
</form>
<!-- END Record uploaded1 -->
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
Gena
Posts: 591
|
| Posted: 10/31/2008, 10:31 AM |
|
all seems good.
The only probably problem I see is that you have
`Imagewidth` tinytext,
`Imageheight` tinytext,
in your table. So I am not sure if it can be problem. BTW take a look at these hidden fields properties and set it as integer or text AND set Control Source Property - specify the source of data for the control, such as the name of a database column.
if it doesn help you can send me *.ccp*.html and *.php file for that page so I can take a look here.
_________________
Gena |
 |
 |
Markie
Posts: 251
|
| Posted: 10/31/2008, 11:14 AM |
|
Dear Gena, I've send you a PM
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
melvyn
Posts: 333
|
| Posted: 10/31/2008, 11:50 AM |
|
******************************
Please note:
In your previous post your code always say: $Component->ImageSize->...
In your pasted code there's no ImageSize, neither hidden or visible, you have ImageWidth and ImageHeigth, so your code must say:
$Component->ImageWidth->SetValue(......);
$Component->ImageHeigth->SetValue(......);
Not $Component->ImageSize->SetValue(......);
*******
Quote :When I use SetValue( ...) I get this error:
Fatal error: Call to a member function SetValue() on a non-object ...
You're right, very, very right!
When we say
$Component-> ImageWidth->SetValue([something]);
we'll get an error, because the event is "AfterProcessFile" and imagewidth isn't part of that component.
Let's change from $Component (the file upload field) to $Container (the form -and remember your form name is uploaded1- ), and let's say:
$Container->ImageWidth->SetValue($width);
$Container->ImageHeigth->SetValue($heigth);
Also can be set:
$uploaded1->ImageWidth->SetValue($width);
$uploaded1->ImageHeigth->SetValue($heigth);
Do this and after that you can type the echo lines looking for the asigned value:
echo "<br > width: ".$width;
echo "<br> heigth: ".$heigth;
echo "<br> container: ".$uploaded1->ImageWidth->GetValue();
exit(0);
Remember that exit(0) will stop the script, we're only looking to see if the record is accepting the value.
Regarding your database definition type, maybe it's need some type conversion. Try the last one.
Another note:
I recommend always use $Container or $Component, so when renaming a form everything get renamed, there's not collateral issues because $container will always refer to the parent container.
But when you use the form name, you'll get auto completion of available components, functions and variables. Just type $uploaded1-> and text completion will show avaible variables and functions; $uploaded1->ImageWidth-> will show you available functions as SetValue and GetValue.
So, I recomend the last one when you need to test/debug
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com |
 |
 |
Markie
Posts: 251
|
| Posted: 10/31/2008, 12:09 PM |
|
Hi Melvyn, you're a wise and very helpfull person and I admire that !
with AfterProcessFile:
$imagesize = "uploaded/".$uploaded1->FileUpload1->GetValue();
list($width, $height) = getimagesize($imagesize); // Get new dimensions
$Container->ImageWidth->SetValue($width);
$Container->ImageHeight->SetValue($height);
echo "<br > width: ".$width;
echo "<br> heigth: ".$height;
echo "<br> container: ".$uploaded1->ImageWidth->GetValue();
exit(0);
I get good results. However, I still don't get any result in my database field
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
melvyn
Posts: 333
|
| Posted: 10/31/2008, 12:15 PM |
|
So, we're closer now 
Go to your DB and change `Imagewidth` and `Imageheight` to integer or tinyint, let's see.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com |
 |
 |
Markie
Posts: 251
|
| Posted: 10/31/2008, 12:35 PM |
|
Melvyn, I get the point !
There's still no result in my database field but I think I have to try all the options (varchar, tinyint, int, float etc.) and I'm confident it will work soon. Too bad there's a lack of documentation with regard to this topic.
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
melvyn
Posts: 333
|
| Posted: 10/31/2008, 12:39 PM |
|
Maybe it's not the database type. You have two hidden fields, each of them has it's own datatype (html/php). Set their datatype as Integer (in ccs) no matter which type is set in the database.
_________________
Melvyn Perez
Puro Codigo
http://purocodigo.com |
 |
 |
Markie
Posts: 251
|
| Posted: 11/01/2008, 1:40 AM |
|
Thanks Melvyn and Gena, the problem is solved !
_________________
The Netherlands, GMT+1
Tools: CCS 5.1, Windows 7, Navicat, Ultraedit
Local server: XAMPP with Apache, php and MySQL
Webserver: Windows 2008 IIS 7, php and MySQL |
 |
 |
|