switch ($_FILES['photo']['type'])
{
case 'image/jpeg':
$image = imagecreatefromjpeg($userImage);
$ext = '.jpg';
break;
case 'image/jpg':
$image = imagecreatefromjpeg($userImage);
$ext = '.jpg';
break;<?php
function MakeDateForDb($date = '11-12-1969')
{
// $date is a string like 01-22-1975.
if (strpos($date, '-'))
{
$dateArray = explode('-', $date);
}
else if (strpos($date, '/'))
{
$dateArray = explode('/', $date);
}
else
{
return $this->FormatMessage($this->LanguageArray[27]);
}
$dateArray = explode('-', $date);
// $dateArray is somethink like [0]=01, [1]=22, [2]=1975
// make a unix timestamp out of the original date string.
$timestamp = mktime(0, 0, 0, $dateArray[0], $dateArray[1], $dateArray[2]);
echo $timestamp;
}
MakeDateForDb();
?>$dateArray = explode('-', $date);it was already mentioned in this thread, but once again:
Changing of the userimage is not possible if the type of the new image is .jpg.
Which surprise that this §"$"§$ Browser doesn´t even handle the file types correctly.case 'image/pjpeg': $image = imagecreatefromjpeg($userImage); $ext = '.jpg'; break;
I think you try it with this format : 07/13/1967. This doesn´t work because of an error in the function.
Just comment out this line:
$dateArray = explode('-', $date);
because it overrides the if clauses above.
function MakeDateForDb($date)
{
// $date is a string like 01-22-1975.
if (strpos($date, '-'))
{
$dateArray = explode('-', $date);
}
else if (strpos($date, '/'))
{
$dateArray = explode('/', $date);
}
else
{
return $this->FormatMessage($this->LanguageArray[27]);
}
$dateArray = explode('-', $date);
// $dateArray is somethink like [0]=01, [1]=22, [2]=1975
// make a unix timestamp out of the original date string.
$timestamp = mktime(0, 0, 0, $dateArray[0], $dateArray[1], $dateArray[2]);
return $timestamp;
}
function MakeDateForDb($date)
{
// $date is a string like 01-22-1975.
if (strpos($date, '-'))
{
$dateArray = explode('-', $date);
}
else if (strpos($date, '/'))
{
$dateArray = explode('/', $date);
}
else
{
return $this->FormatMessage($this->LanguageArray[27]);
}
// $dateArray is somethink like [0]=01, [1]=22, [2]=1975
// make a unix timestamp out of the original date string.
$timestamp = mktime(0, 0, 0, $dateArray[0], $dateArray[1], $dateArray[2]);
return $timestamp;
}
Good thing
Changing of the userimage is not possible if the type of the new image is .jpg. I already tried to add another mime type like this:
switch ($_FILES['photo']['type']) { case 'image/jpeg': $image = imagecreatefromjpeg($userImage); $ext = '.jpg'; break; case 'image/jpg': $image = imagecreatefromjpeg($userImage); $ext = '.jpg'; break;
You can do the same thing with fewer line
switch ($_FILES['photo']['type'])
{
case 'image/jpeg':
case 'image/jpg':
$image = imagecreatefromjpeg($userImage);
$ext = '.jpg';
break;
$modx->setPlaceholder('user.'.$key, strftime('%m-%d-%Y', $value));
// CREDIT : Guillaume for not format an empty date
$value==0?'':$modx->setPlaceholder('user.'.$key, strftime('%m-%d-%Y', $value));
foreach ($generalElementsArray as $id => $field)
{
if ($field == 'photo')
{
if ($_FILES['photo']['name'] !== '' && !empty($_FILES['photo']['name']))
{
$_POST['photo'] = $this->CreateUserImage();
if (!empty($this->Report))
{
return;
}
}
}
if (isset($_POST[$field]) && ($_POST[$field] !== ''))
{
if ($field == 'dob')
{
$_POST['dob'] = $this->MakeDateForDb($_POST['dob']);
}
// CREDIT: Mike Reid (aka Pixelchutes) for the string escape code.
$generalElementsUpdate[] = " `".$field."` = '".$modx->db->escape(stripslashes(htmlentities(trim($_POST[$field]), ENT_QUOTES)))."'";
}
else
{
unset ($generalElementsArray[$id]);
}
}
// CREDIT: Guillaume to delete data and for code optimisation
foreach ($generalElementsArray as $field)
{
if ($field == 'photo')
{
if ($_FILES['photo']['name'] !== '' && !empty($_FILES['photo']['name']))
{
$_POST['photo'] = $this->CreateUserImage();
if (!empty($this->Report))
{
return;
}
}
}
if ($field == 'dob' && trim($_POST['dob'])!='') // for not format an empty date else date is 0 (01-01-1970)
{
$_POST['dob'] = $this->MakeDateForDb($_POST['dob']);
}
if ($field!='photo' || ($_FILES['photo']['name'] !== '' && !empty($_FILES['photo']['name']))) // for update db with value and blank value (except if the field is 'photo')
// CREDIT: Mike Reid (aka Pixelchutes) for the string escape code.
$generalElementsUpdate[] = " `".$field."` = '".$modx->db->escape(stripslashes(htmlentities(trim($_POST[$field]), ENT_QUOTES)))."'";
}