473,594 Members | 2,713 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Need help with some OO php

Hello Everyone,

I'm trying to debug someone elses php code. I'm actually a Perl
programmer, with OO experience, but not in php.

The code is supposed to upload a photo from a form and save it both on
the file system and in a mySql database. 90% of the time it works just
fine. But for some reason, with some photos, it doesn't work. The
image never shows up on the filesystem and there is no entry in the
database. I feel it's a problem with the image because if I resave the
image in photoshop with a lower resolution -- it uploads just fine. I
don't completely understand why this resaving of the image works though
because the orriginal size of the image is still well under the
FileSize Max, which according to the code below is 3.5mb.
I'm not including all of the code because there is a lot. I believe
I've pasted the correct snips below though. If you need any more info,
please let me know.

My main quesitons are:
1. How/where in the code, is the image file being written to the disk?
I don't see the 'imagejpeg' function I am familar with.
2. I want to put in some debugging print statments to figure out what's
going on -- maybe have a log file being written to but I don't know how
to go about that in OO php? Can someone give me an example to do this?

Thanks for any help and guidance!

M

-- Snip -- This is the code in the page that accepts the photos from a
form. There are actually 7 photo fields on that page. This is just one
of them.
$this->Image2 = new clsControl(ccsI mage, "Image2", "Image2", ccsText,
"", CCGetRequestPar am("Image2", $Method));
$this->photo2 = new clsFileUpload(" photo2", "photo2", "temp/",
"photos/", "*.jpg", "", 3500000);

-- Snip -- This is the complete clsFileUpload Class

//clsFileUpload Class @0-81C1F4F1
class clsFileUpload
{
var $Name;
var $Caption;
var $Visible;
var $Required;

var $TemporaryFolde r;
var $FileFolder;
var $AllowedMask; // @deprecated , use AllowedFileMask s property
var $AllowedFileMas ks;
var $DisallowedFile Masks;
var $FileSizeLimit;
var $Value;
var $Text;
var $State;

var $CCSEvents = "";
var $CCSEventResult ;

function clsFileUpload($ Name, $Caption, $TemporaryFolde r,
$FileFolder, $AllowedFileMas ks, $DisallowedFile Masks, $FileSizeLimit)
{

$this->Errors = new clsErrors;

$this->Name = $Name;
$this->Visible = true;
$this->Caption = $Caption;
if(substr($Temp oraryFolder, 0, 1) == "%") {
$TemporaryFolde r = substr($Tempora ryFolder, 1);
$TemporaryFolde r = getenv($Tempora ryFolder);
}
$this->TemporaryFolde r = $TemporaryFolde r;
if(substr($File Folder, 0, 1) == "%") {
$FileFolder = substr($FileFol der, 1);
$FileFolder = getenv($FileFol der);
}
$this->FileFolder = $FileFolder;
$this->AllowedFileMas ks = $AllowedFileMas ks;
$this->AllowedMask = & $this->AllowedFileMas ks;
$this->DisallowedFile Masks = $DisallowedFile Masks;
$this->FileSizeLimi t = $FileSizeLimit;
$this->Value = "";
$this->Text = "";
$this->Required = false;

$FileName = "";
$FieldName = $this->Caption;
if( !is_dir($Tempor aryFolder) ) {
$this->Errors->addError("Unab le to upload the file specified in "
.. $FieldName . " - temporary upload folder doesn't exist.");
} else if( !is_writable($T emporaryFolder) ) {
$this->Errors->addError("Insu fficient filesystem permissions to
upload the file specified in " . $FieldName . " into temporary
folder.");
} else if( !is_dir($FileFo lder) ) {
$this->Errors->addError("Unab le to upload the file specified in "
.. $FieldName . " - upload folder doesn't exist.");
} else if( !is_writable($F ileFolder) ) {
$this->Errors->addError("Insu fficient filesystem permissions to
upload the file specified in " . $FieldName . ".");
}

}

function Validate()
{
$validation = true;
if($this->Required && $this->Value === "" && $this->Errors->Count() == 0)
{
$FieldName = $this->Caption;
$this->Errors->addError("Th e file attachment in field " .
$FieldName . " is required.");
}
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "OnValidate ");
return ($this->Errors->Count() == 0);
}
function Upload($RowNumb er = "")
{
global $HTTP_POST_FILE S;
$FieldName = $this->Caption;
if(strlen($RowN umber)) {
$ControlName = $this->Name . "_" . $RowNumber;
$FileControl = $this->Name . "_File_" . $RowNumber;
$DeleteControl = $this->Name . "_Delete_" . $RowNumber;
} else {
$ControlName = $this->Name;
$FileControl = $this->Name . "_File";
$DeleteControl = $this->Name . "_Delete";
}

$SessionName = CCGetParam($Con trolName);
$this->State = CCGetSession($S essionName);

if (strlen(CCGetPa ram($DeleteCont rol))) {
// delete file from folder
$ActualFileName = $this->State[0];
if( file_exists($th is->FileFolder . $ActualFileName ) ) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"BeforeDeleteFi le");
unlink($this->FileFolder . $ActualFileName );
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"AfterDeleteFil e");
} else if ( file_exists($th is->TemporaryFolde r . $ActualFileName ) ) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"BeforeDeleteFi le");
unlink($this->TemporaryFolde r . $ActualFileName );
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"AfterDeleteFil e");
}
$this->Value = ""; $this->Text = "";
$this->State[0] = "";
} else if (isset ($HTTP_POST_FIL ES[$FileControl])
&& $HTTP_POST_FILE S[$FileControl]["tmp_name"] != "none"
&& strlen ($HTTP_POST_FIL ES[$FileControl]["tmp_name"])) {
$this->Value = ""; $this->Text = "";
$FileName = $HTTP_POST_FILE S[$FileControl]["name"];
$GoodFileMask = 1;
$meta_character s = array("*" =".+", "?" =".", "\\" ="\\\\",
"^" ="\\^", "\$" ="\\\$", "." ="\\.", "[" ="\\[", "]" ="\\]",
"|" ="\\|", "(" ="\\(", ")" ="\\)", "{" ="\\{", "}" ="\\}",
"+" ="\\+", "-" ="\\-");
if ($this->AllowedFileMas ks != "") {
$GoodFileMask = 0;
$FileMasks=spli t(';', $this->AllowedFileMas ks);
foreach ($FileMasks as $FileMask) {
$FileMask =
preg_replace("/(\\*|\\?|\\\\|\ \^|\\\$|\\.|\\[|\\]|\\||\\(|\\)|\\ {|\\}|\\+|\\-)/ei",
"\$meta_charact ers['\\1']", $FileMask);
if (preg_match("/^$FileMask$/i", $FileName)) {
$GoodFileMask = 1;
break;
}
}
}
if ($GoodFileMask && $this->DisallowedFile Masks != "") {
$FileMasks=spli t(';', $this->DisallowedFile Masks);
foreach ($FileMasks as $FileMask) {
$FileMask =
preg_replace("/(\\*|\\?|\\\\|\ \^|\\\$|\\.|\\[|\\]|\\||\\(|\\)|\\ {|\\}|\\+|\\-)/ei",
"\$meta_charact ers['\\1']", $FileMask);
if (preg_match("/^$FileMask$/i", $FileName)) {
$GoodFileMask = 0;
break;
}
}
}
if($HTTP_POST_F ILES[$FileControl]["size"] $this->FileSizeLimi t) {
$this->Errors->addError("Th e file size in field " . $FieldName
.. " is too large.");
} else if (!$GoodFileMask ) {
$this->Errors->addError("Th e file type specified in field " .
$FieldName . " is not allowed.");
} else {
// move uploaded file to temporary folder
$file_exists = true;
$index = 0;
while($file_exi sts) {
$ActualFileName = date("YmdHis") . $index . "." . $FileName;
$file_exists = file_exists($Ac tualFileName);
$index++;
}
if( copy($HTTP_POST _FILES[$FileControl]["tmp_name"],
$this->TemporaryFolde r . $ActualFileName ) ) {
$this->Value = $ActualFileName ;
$this->Text = $ActualFileName ;
if(strlen($this->State[0])) {
if(file_exists( $this->TemporaryFolde r . $this->State[0])) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"BeforeDeleteFi le");
unlink($this->TemporaryFolde r . $this->State[0]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"AfterDeleteFil e");
$this->State[0] = $ActualFileName ;
} else {
if(!is_dir($thi s->TemporaryFolde r . $this->State[1]) &&
file_exists($th is->TemporaryFolde r . $this->State[1])) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"BeforeDeleteFi le");
unlink($this->TemporaryFolde r . $this->State[1]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"AfterDeleteFil e");
}
$this->State[1] = $ActualFileName ;
}
} else {
$this->State[0] = $ActualFileName ;
}
} else {
$this->Errors->addError("Insu fficient filesystem permissions
to upload the file specified in " . $FieldName . " into temporary
folder.");
}
}
} else {
$this->SetValue(strle n($this->State[1]) ? $this->State[1] :
$this->State[0]);
}
}

function Move()
{
if (strlen($this->Value) && !file_exists($t his->FileFolder .
$this->Value)) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"BeforeProcessF ile");
$FileName = $this->GetFileName( );
$FieldName = $this->Caption;
if (!file_exists($ this->TemporaryFolde r . $this->Value)) {
$this->Errors->addError("Th e file " . $FileName . " specified
in " . $FieldName . " was not found.");
} else if (!@copy($this->TemporaryFolde r . $this->Value,
$this->FileFolder . $this->Value)) {
$this->Errors->addError("Insu fficient filesystem permissions to
upload the file specified in " . $FieldName . ".");
} else if (strlen($this->State[1])) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"BeforeDeleteFi le");
unlink($this->FileFolder . $this->State[0]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"AfterDeleteFil e");
}
if($this->Errors->Count() == 0 &&
file_exists($th is->TemporaryFolde r . $this->Value)) {
unlink($this->TemporaryFolde r . $this->Value);
}
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "AfterProcessFi le");
}
}

function Delete()
{
if( !is_dir($this->FileFolder . $this->State[0]) &&
file_exists($th is->FileFolder . $this->State[0]) ) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "BeforeDeleteFi le");
unlink($this->FileFolder . $this->State[0]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "AfterDeleteFil e");
} else if ( !is_dir($this->TemporaryFolde r . $this->State[0]) &&
file_exists($th is->TemporaryFolde r . $this->State[0]) ) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "BeforeDeleteFi le");
unlink($this->TemporaryFolde r . $this->State[0]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "AfterDeleteFil e");
}
if( !is_dir($this->FileFolder . $this->State[1]) &&
file_exists($th is->FileFolder . $this->State[1]) ) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "BeforeDeleteFi le");
unlink($this->FileFolder . $this->State[1]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "AfterDeleteFil e");
} else if ( !is_dir($this->TemporaryFolde r . $this->State[1]) &&
file_exists($th is->TemporaryFolde r . $this->State[1]) ) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "BeforeDeleteFi le");
unlink($this->TemporaryFolde r . $this->State[1]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "AfterDeleteFil e");
}
}

function Show($RowNumber = "")
{
global $Tpl;
if($this->Visible)
{
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "BeforeShow ");

if(!$this->Visible) {
$Tpl->setblockvar("F ileUpload " . $this->Name, "");
return;
}

if(strlen($RowN umber)) {
$ControlName = $this->Name . "_" . $RowNumber;
$FileControl = $this->Name . "_File_" . $RowNumber;
$DeleteControl = $this->Name . "_Delete_" . $RowNumber;
} else {
$ControlName = $this->Name;
$FileControl = $this->Name . "_File";
$DeleteControl = $this->Name . "_Delete";
}

$SessionName = CCGetParam($Con trolName);
if(!strlen($Ses sionName)) {
srand ((double) microtime() * 1000000);
$random_value = rand();
$SessionName = "FileUpload " . $random_value . date("dHis");
$this->State = array($this->Value, "");
}

CCSetSession($S essionName, $this->State);

$Tpl->SetVar("State" , $SessionName);
$Tpl->SetVar("Contro lName", $ControlName);
$Tpl->SetVar("FileCo ntrol", $FileControl);
$Tpl->SetVar("Delete Control", $DeleteControl) ;
if (strlen($this->Value) ) {
$Tpl->SetVar("Actual FileName", $this->Value);
$Tpl->SetVar("FileNa me", $this->GetFileName()) ;
$Tpl->SetVar("FileSi ze", $this->GetFileSize()) ;
$Tpl->parse("FileUpl oad " . $this->Name . "/Info", false);
if($this->Required) {
$Tpl->parse("FileUpl oad " . $this->Name . "/Upload", false);
$Tpl->setblockvar("F ileUpload " . $this->Name .
"/DeleteControl", "");
} else {
$Tpl->setblockvar("F ileUpload " . $this->Name . "/Upload", "");
$Tpl->parse("FileUpl oad " . $this->Name . "/DeleteControl", false);
}
} else {
$Tpl->parse("FileUpl oad " . $this->Name . "/Upload", false);
$Tpl->setblockvar("F ileUpload " . $this->Name . "/Info", "");
$Tpl->setblockvar("F ileUpload " . $this->Name . "/DeleteControl", "");
}

$Tpl->Parse("FileUpl oad " . $this->Name, false);
}
else
{
$Tpl->setblockvar("F ileUpload " . $this->Name, "");
}
}

function SetValue($Value ) {
$this->Text = $Value;
$this->Value = $Value;
$this->State[0] = $Value;
if(strlen($Valu e)
&& !file_exists($t his->TemporaryFolde r . $Value)
&& !file_exists($t his->FileFolder . $Value)) {
$FileName = $this->GetFileName( );
$FieldName = $this->Caption;
$this->Errors->addError("Th e file " . $FileName . " specified
in " . $FieldName . " was not found.");
}
}

function SetText($Text) {
$this->SetValue($Text );
}

function GetValue() {
return $this->Value;
}

function GetText() {
return $this->Text;
}

function GetFileName() {
return preg_match("/^\d{14,}\./", $this->Value) ?
substr($this->Value, strpos($this->Value, ".") + 1) : $this->Value;
}

function GetFileSize() {
$filesize = 0;
if( file_exists($th is->FileFolder . $this->Value) ) {
$filesize = filesize($this->FileFolder . $this->Value);
} else if ( file_exists($th is->TemporaryFolde r . $this->Value) ) {
$filesize = filesize($this->TemporaryFolde r . $this->Value);
}
return $filesize;
}

}

//End clsFileUpload Class


May 9 '07 #1
3 2188
At Wed, 09 May 2007 11:39:43 -0400, Milagro let his monkeys type:
Hello Everyone,

I'm trying to debug someone elses php code. I'm actually a Perl
programmer, with OO experience, but not in php.

The code is supposed to upload a photo from a form and save it both on
the file system and in a mySql database. 90% of the time it works just
fine. But for some reason, with some photos, it doesn't work. The
image never shows up on the filesystem and there is no entry in the
database. I feel it's a problem with the image because if I resave the
image in photoshop with a lower resolution -- it uploads just fine. I
don't completely understand why this resaving of the image works though
because the orriginal size of the image is still well under the
FileSize Max, which according to the code below is 3.5mb.
I'm not including all of the code because there is a lot. I believe
I've pasted the correct snips below though. If you need any more info,
please let me know.

My main quesitons are:
1. How/where in the code, is the image file being written to the disk?
I don't see the 'imagejpeg' function I am familar with.
2. I want to put in some debugging print statments to figure out what's
going on -- maybe have a log file being written to but I don't know how
to go about that in OO php? Can someone give me an example to do this?

Thanks for any help and guidance!

M

-- Snip -- This is the code in the page that accepts the photos from a
form. There are actually 7 photo fields on that page. This is just one
of them.
$this->Image2 = new clsControl(ccsI mage, "Image2", "Image2", ccsText,
"", CCGetRequestPar am("Image2", $Method));
$this->photo2 = new clsFileUpload(" photo2", "photo2", "temp/",
"photos/", "*.jpg", "", 3500000);

-- Snip -- This is the complete clsFileUpload Class

//clsFileUpload Class @0-81C1F4F1
class clsFileUpload
{
var $Name;
var $Caption;
var $Visible;
var $Required;

var $TemporaryFolde r;
var $FileFolder;
var $AllowedMask; // @deprecated , use AllowedFileMask s property
var $AllowedFileMas ks;
var $DisallowedFile Masks;
var $FileSizeLimit;
var $Value;
var $Text;
var $State;

var $CCSEvents = "";
var $CCSEventResult ;

function clsFileUpload($ Name, $Caption, $TemporaryFolde r,
$FileFolder, $AllowedFileMas ks, $DisallowedFile Masks, $FileSizeLimit)
{

$this->Errors = new clsErrors;

$this->Name = $Name;
$this->Visible = true;
$this->Caption = $Caption;
if(substr($Temp oraryFolder, 0, 1) == "%") {
$TemporaryFolde r = substr($Tempora ryFolder, 1);
$TemporaryFolde r = getenv($Tempora ryFolder);
}
$this->TemporaryFolde r = $TemporaryFolde r;
if(substr($File Folder, 0, 1) == "%") {
$FileFolder = substr($FileFol der, 1);
$FileFolder = getenv($FileFol der);
}
$this->FileFolder = $FileFolder;
$this->AllowedFileMas ks = $AllowedFileMas ks;
$this->AllowedMask = & $this->AllowedFileMas ks;
$this->DisallowedFile Masks = $DisallowedFile Masks;
$this->FileSizeLimi t = $FileSizeLimit;
$this->Value = "";
$this->Text = "";
$this->Required = false;

$FileName = "";
$FieldName = $this->Caption;
if( !is_dir($Tempor aryFolder) ) {
$this->Errors->addError("Unab le to upload the file specified in "
. $FieldName . " - temporary upload folder doesn't exist.");
} else if( !is_writable($T emporaryFolder) ) {
$this->Errors->addError("Insu fficient filesystem permissions to
upload the file specified in " . $FieldName . " into temporary
folder.");
} else if( !is_dir($FileFo lder) ) {
$this->Errors->addError("Unab le to upload the file specified in "
. $FieldName . " - upload folder doesn't exist.");
} else if( !is_writable($F ileFolder) ) {
$this->Errors->addError("Insu fficient filesystem permissions to
upload the file specified in " . $FieldName . ".");
}

}

function Validate()
{
$validation = true;
if($this->Required && $this->Value === "" && $this->Errors->Count() == 0)
{
$FieldName = $this->Caption;
$this->Errors->addError("Th e file attachment in field " .
$FieldName . " is required.");
}
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "OnValidate ");
return ($this->Errors->Count() == 0);
}
function Upload($RowNumb er = "")
{
global $HTTP_POST_FILE S;
$FieldName = $this->Caption;
if(strlen($RowN umber)) {
$ControlName = $this->Name . "_" . $RowNumber;
$FileControl = $this->Name . "_File_" . $RowNumber;
$DeleteControl = $this->Name . "_Delete_" . $RowNumber;
} else {
$ControlName = $this->Name;
$FileControl = $this->Name . "_File";
$DeleteControl = $this->Name . "_Delete";
}

$SessionName = CCGetParam($Con trolName);
$this->State = CCGetSession($S essionName);

if (strlen(CCGetPa ram($DeleteCont rol))) {
// delete file from folder
$ActualFileName = $this->State[0];
if( file_exists($th is->FileFolder . $ActualFileName ) ) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"BeforeDeleteFi le");
unlink($this->FileFolder . $ActualFileName );
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"AfterDeleteFil e");
} else if ( file_exists($th is->TemporaryFolde r . $ActualFileName ) ) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"BeforeDeleteFi le");
unlink($this->TemporaryFolde r . $ActualFileName );
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"AfterDeleteFil e");
}
$this->Value = ""; $this->Text = "";
$this->State[0] = "";
} else if (isset ($HTTP_POST_FIL ES[$FileControl])
&& $HTTP_POST_FILE S[$FileControl]["tmp_name"] != "none"
&& strlen ($HTTP_POST_FIL ES[$FileControl]["tmp_name"])) {
$this->Value = ""; $this->Text = "";
$FileName = $HTTP_POST_FILE S[$FileControl]["name"];
$GoodFileMask = 1;
$meta_character s = array("*" =".+", "?" =".", "\\" ="\\\\",
"^" ="\\^", "\$" ="\\\$", "." ="\\.", "[" ="\\[", "]" ="\\]",
"|" ="\\|", "(" ="\\(", ")" ="\\)", "{" ="\\{", "}" ="\\}",
"+" ="\\+", "-" ="\\-");
if ($this->AllowedFileMas ks != "") {
$GoodFileMask = 0;
$FileMasks=spli t(';', $this->AllowedFileMas ks);
foreach ($FileMasks as $FileMask) {
$FileMask =
preg_replace("/(\\*|\\?|\\\\|\ \^|\\\$|\\.|\\[|\\]|\\||\\(|\\)|\\ {|\\}|\\+|\\-)/ei",
"\$meta_charact ers['\\1']", $FileMask);
if (preg_match("/^$FileMask$/i", $FileName)) {
$GoodFileMask = 1;
break;
}
}
}
if ($GoodFileMask && $this->DisallowedFile Masks != "") {
$FileMasks=spli t(';', $this->DisallowedFile Masks);
foreach ($FileMasks as $FileMask) {
$FileMask =
preg_replace("/(\\*|\\?|\\\\|\ \^|\\\$|\\.|\\[|\\]|\\||\\(|\\)|\\ {|\\}|\\+|\\-)/ei",
"\$meta_charact ers['\\1']", $FileMask);
if (preg_match("/^$FileMask$/i", $FileName)) {
$GoodFileMask = 0;
break;
}
}
}
if($HTTP_POST_F ILES[$FileControl]["size"] $this->FileSizeLimi t) {
$this->Errors->addError("Th e file size in field " . $FieldName
. " is too large.");
} else if (!$GoodFileMask ) {
$this->Errors->addError("Th e file type specified in field " .
$FieldName . " is not allowed.");
} else {
// move uploaded file to temporary folder
$file_exists = true;
$index = 0;
while($file_exi sts) {
$ActualFileName = date("YmdHis") . $index . "." . $FileName;
$file_exists = file_exists($Ac tualFileName);
$index++;
}
if( copy($HTTP_POST _FILES[$FileControl]["tmp_name"],
$this->TemporaryFolde r . $ActualFileName ) ) {
$this->Value = $ActualFileName ;
$this->Text = $ActualFileName ;
if(strlen($this->State[0])) {
if(file_exists( $this->TemporaryFolde r . $this->State[0])) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"BeforeDeleteFi le");
unlink($this->TemporaryFolde r . $this->State[0]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"AfterDeleteFil e");
$this->State[0] = $ActualFileName ;
} else {
if(!is_dir($thi s->TemporaryFolde r . $this->State[1]) &&
file_exists($th is->TemporaryFolde r . $this->State[1])) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"BeforeDeleteFi le");
unlink($this->TemporaryFolde r . $this->State[1]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"AfterDeleteFil e");
}
$this->State[1] = $ActualFileName ;
}
} else {
$this->State[0] = $ActualFileName ;
}
} else {
$this->Errors->addError("Insu fficient filesystem permissions
to upload the file specified in " . $FieldName . " into temporary
folder.");
}
}
} else {
$this->SetValue(strle n($this->State[1]) ? $this->State[1] :
$this->State[0]);
}
}

function Move()
{
if (strlen($this->Value) && !file_exists($t his->FileFolder .
$this->Value)) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"BeforeProcessF ile");
$FileName = $this->GetFileName( );
$FieldName = $this->Caption;
if (!file_exists($ this->TemporaryFolde r . $this->Value)) {
$this->Errors->addError("Th e file " . $FileName . " specified
in " . $FieldName . " was not found.");
} else if (!@copy($this->TemporaryFolde r . $this->Value,
$this->FileFolder . $this->Value)) {
$this->Errors->addError("Insu fficient filesystem permissions to
upload the file specified in " . $FieldName . ".");
} else if (strlen($this->State[1])) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"BeforeDeleteFi le");
unlink($this->FileFolder . $this->State[0]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents,
"AfterDeleteFil e");
}
if($this->Errors->Count() == 0 &&
file_exists($th is->TemporaryFolde r . $this->Value)) {
unlink($this->TemporaryFolde r . $this->Value);
}
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "AfterProcessFi le");
}
}

function Delete()
{
if( !is_dir($this->FileFolder . $this->State[0]) &&
file_exists($th is->FileFolder . $this->State[0]) ) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "BeforeDeleteFi le");
unlink($this->FileFolder . $this->State[0]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "AfterDeleteFil e");
} else if ( !is_dir($this->TemporaryFolde r . $this->State[0]) &&
file_exists($th is->TemporaryFolde r . $this->State[0]) ) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "BeforeDeleteFi le");
unlink($this->TemporaryFolde r . $this->State[0]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "AfterDeleteFil e");
}
if( !is_dir($this->FileFolder . $this->State[1]) &&
file_exists($th is->FileFolder . $this->State[1]) ) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "BeforeDeleteFi le");
unlink($this->FileFolder . $this->State[1]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "AfterDeleteFil e");
} else if ( !is_dir($this->TemporaryFolde r . $this->State[1]) &&
file_exists($th is->TemporaryFolde r . $this->State[1]) ) {
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "BeforeDeleteFi le");
unlink($this->TemporaryFolde r . $this->State[1]);
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "AfterDeleteFil e");
}
}

function Show($RowNumber = "")
{
global $Tpl;
if($this->Visible)
{
$this->CCSEventResu lt = CCGetEvent($thi s->CCSEvents, "BeforeShow ");

if(!$this->Visible) {
$Tpl->setblockvar("F ileUpload " . $this->Name, "");
return;
}

if(strlen($RowN umber)) {
$ControlName = $this->Name . "_" . $RowNumber;
$FileControl = $this->Name . "_File_" . $RowNumber;
$DeleteControl = $this->Name . "_Delete_" . $RowNumber;
} else {
$ControlName = $this->Name;
$FileControl = $this->Name . "_File";
$DeleteControl = $this->Name . "_Delete";
}

$SessionName = CCGetParam($Con trolName);
if(!strlen($Ses sionName)) {
srand ((double) microtime() * 1000000);
$random_value = rand();
$SessionName = "FileUpload " . $random_value . date("dHis");
$this->State = array($this->Value, "");
}

CCSetSession($S essionName, $this->State);

$Tpl->SetVar("State" , $SessionName);
$Tpl->SetVar("Contro lName", $ControlName);
$Tpl->SetVar("FileCo ntrol", $FileControl);
$Tpl->SetVar("Delete Control", $DeleteControl) ;
if (strlen($this->Value) ) {
$Tpl->SetVar("Actual FileName", $this->Value);
$Tpl->SetVar("FileNa me", $this->GetFileName()) ;
$Tpl->SetVar("FileSi ze", $this->GetFileSize()) ;
$Tpl->parse("FileUpl oad " . $this->Name . "/Info", false);
if($this->Required) {
$Tpl->parse("FileUpl oad " . $this->Name . "/Upload", false);
$Tpl->setblockvar("F ileUpload " . $this->Name .
"/DeleteControl", "");
} else {
$Tpl->setblockvar("F ileUpload " . $this->Name . "/Upload", "");
$Tpl->parse("FileUpl oad " . $this->Name . "/DeleteControl", false);
}
} else {
$Tpl->parse("FileUpl oad " . $this->Name . "/Upload", false);
$Tpl->setblockvar("F ileUpload " . $this->Name . "/Info", "");
$Tpl->setblockvar("F ileUpload " . $this->Name . "/DeleteControl", "");
}

$Tpl->Parse("FileUpl oad " . $this->Name, false);
}
else
{
$Tpl->setblockvar("F ileUpload " . $this->Name, "");
}
}

function SetValue($Value ) {
$this->Text = $Value;
$this->Value = $Value;
$this->State[0] = $Value;
if(strlen($Valu e)
&& !file_exists($t his->TemporaryFolde r . $Value)
&& !file_exists($t his->FileFolder . $Value)) {
$FileName = $this->GetFileName( );
$FieldName = $this->Caption;
$this->Errors->addError("Th e file " . $FileName . " specified
in " . $FieldName . " was not found.");
}
}

function SetText($Text) {
$this->SetValue($Text );
}

function GetValue() {
return $this->Value;
}

function GetText() {
return $this->Text;
}

function GetFileName() {
return preg_match("/^\d{14,}\./", $this->Value) ?
substr($this->Value, strpos($this->Value, ".") + 1) : $this->Value;
}

function GetFileSize() {
$filesize = 0;
if( file_exists($th is->FileFolder . $this->Value) ) {
$filesize = filesize($this->FileFolder . $this->Value);
} else if ( file_exists($th is->TemporaryFolde r . $this->Value) ) {
$filesize = filesize($this->TemporaryFolde r . $this->Value);
}
return $filesize;
}

}

//End clsFileUpload Class

But, what's important here, do you know what the accepted upload size is
in php.ini? (check using phpinfo(), variable upload_max_file size). If
that's under the form's limit, this might explain why the uploads fail on
originals and succeed on the resized/recompressed versions.
I think the default might be 2megs.
The size specified in the form isn't a hard limit per se, the
upload_max_file size in php.ini is.

HTH
Sh.

PS can't help but get the idea (haven't read all the posted code in
detail) the class you got is rather, errm, huge for what it's supposed to
do. And not that easy to decipher. Documenting's not the programmer's
first priority I suppose...

Good luck, let us know what you find!
Sh.
May 9 '07 #2
>
But, what's important here, do you know what the accepted upload size is
in php.ini? (check using phpinfo(), variable upload_max_file size). If
that's under the form's limit, this might explain why the uploads fail on
originals and succeed on the resized/recompressed versions.
I think the default might be 2megs.
The size specified in the form isn't a hard limit per se, the
upload_max_file size in php.ini is.

HTH
Sh.

Thanks! I think you hit the nail on the head. upload_max_file size is
indeed set to 2mb and all the files I'm having problems with are over
2mb.

Two more questions. Is there any downside to changing this variable in
php.ini to a higher value [say 3mb] (other then it consuming more
server resources) ?
This is a dedicated server with a speedy processor and 2gb of Ram.
And if I do change the value in php.ini do I have to restart some
process or does php pick up those settings right away?

Thanks again.
M

May 9 '07 #3
At Wed, 09 May 2007 15:12:04 -0400, Milagro let his monkeys type:
>>
But, what's important here, do you know what the accepted upload size is
in php.ini? (check using phpinfo(), variable upload_max_file size). If
that's under the form's limit, this might explain why the uploads fail on
originals and succeed on the resized/recompressed versions.
I think the default might be 2megs.
The size specified in the form isn't a hard limit per se, the
upload_max_fil esize in php.ini is.

HTH
Sh.


Thanks! I think you hit the nail on the head. upload_max_file size is
indeed set to 2mb and all the files I'm having problems with are over
2mb.

Two more questions. Is there any downside to changing this variable in
php.ini to a higher value [say 3mb] (other then it consuming more
server resources) ?
Not that I am aware of, no.
This is a dedicated server with a speedy processor and 2gb of Ram.
And if I do change the value in php.ini do I have to restart some
process or does php pick up those settings right away?

Thanks again.
M
It all boils down to the number of concurrent users I suppose, you could
benchmark the performance if you expect load/resource issues.

Restart apache after any change to the config files.

On linux, there probably is a script in /etc/init.d/ or /etc/rc.d/init.d/
named apache, apache2 or httpd. On my Gentoo box the proper command would
be /etc/init.d/apache2 restart.

On windows XP machines I know it's possible to restart a service in
Control Panel/Administrative Tools/Services, and perhaps from the command
line. Been too long to remember exactly.

Sh.

May 9 '07 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
2423
by: Sofia | last post by:
My name is Sofia and I have for many years been running a personals site, together with my partner, on a non-profit basis. The site is currently not running due to us emigrating, but during its last year we got traffic of between 2000 - 2500 unique visitors per day. We are now about to re-launch the site from Sweden and we need to purchase a script to run it. Having looked at what is available on the net I have realised that we need a...
7
4378
by: Mike Kamermans | last post by:
I hope someone can help me, because what I'm going through at the moment trying to edit XML documents is enough to make me want to never edit XML again. I'm looking for an XML editor that has a few features that you'd expect in any editor, except nearly none of them seem to have: 1 - Search and repalce with Regular Expressions. 2 - Search and Replace in an Xpath context. 3 - User specified tag-generation for either on a...
15
3666
by: drdoubt | last post by:
using namespace std In my C++ program, even after applying , I need to use the std namespace with the scope resolution operator, like, std::cout, std::vector. This I found a little bit cumbersome to always include std. I somewhere found a trick to overcome this problem. By using using std::cout;
9
2917
by: sk | last post by:
I have an applicaton in which I collect data for different parameters for a set of devices. The data are entered into a single table, each set of name, value pairs time-stamped and associated with a device. The definition of the table is as follows: CREATE TABLE devicedata ( device_id int NOT NULL REFERENCES devices(id), -- id in the device
3
2614
by: Bob.Henkel | last post by:
I write this to tell you why we won't use postgresql even though we wish we could at a large company. Don't get me wrong I love postgresql in many ways and for many reasons , but fact is fact. If you need more detail I can be glad to prove all my points. Our goal is to make logical systems. We don't want php,perl, or c++ making all the procedure calls and having the host language to be checking for errors and handleing all the...
3
10626
by: google | last post by:
I have a database with four table. In one of the tables, I use about five lookup fields to get populate their dropdown list. I have read that lookup fields are really bad and may cause problems that are hard to find. The main problem I am having right now is that I have a report that is sorted by one of these lookup fields and it only displays the record's ID number. When I add the source table to the query it makes several records...
4
7394
by: Phil | last post by:
k, here is my issue.. I have BLOB data in SQL that needs to be grabbed and made into a TIF file and placed on the client (could be in temp internet dir). The reason we need it in TIF format is there are multiple pages per invoice. How can I grab the data, make the TIF, place it on the client and then Open with the clients default program for veiwing TIF's (usually Microsoft Picture and Fax Viewer). Please help.
8
1827
by: Sai Kit Tong | last post by:
In the article, the description for "Modiy DLL That Contains Consumers That Use Managed Code and DLL Exports or Managed Entry Points" suggests the creation of the class ManagedWrapper. If I need to build multiple mixed mode dll's used by a consumer application, do I have to implement multiple ManagedWrapper's (each embedded in indiviudal DLL project) and call all of them in my consumer application?
2
1944
by: Michael R. Pierotti | last post by:
Dim reg As New Regex("^\d{1,3}.\d{1,3}.\d{1,3}.\d{1,3}$") Dim m As Match = reg.Match(txtIPAddress.Text) If m.Success Then 'No need to do anything here Else MessageBox.Show("You need to enter a valid IP Address", "Error!", MessageBoxButtons.OK, MessageBoxIcon.Hand) txtIPAddress.Focus() Return End If
0
3936
by: U S Contractors Offering Service A Non-profit | last post by:
Brilliant technology helping those most in need Inbox Reply U S Contractors Offering Service A Non-profit show details 10:37 pm (1 hour ago) Brilliant technology helping those most in need Inbox Reply from Craig Somerford <uscos@2barter.net> hide details 10:25 pm (3 minutes ago)
0
7946
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
7876
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8251
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8372
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8003
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8234
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
5739
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5408
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
3859
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.