diff --git a/src/CoreFields/ImageField.php b/src/CoreFields/ImageField.php
index 349963f..b0fe975 100644
--- a/src/CoreFields/ImageField.php
+++ b/src/CoreFields/ImageField.php
@@ -50,418 +50,131 @@ class ImageField extends PhangoField {
//Check if the image is correct..
- function check($image)
+ function check($fake_image)
{
//Only accept jpeg, gif y png
- if(isset($_FILES[$this->name_component]['tmp_name']))
+ //Rewrite old_image
+
+ $file_name=$this->name_component.'_file';
+
+ $old_image='';
+
+ if($this->update)
{
- $name_image=$_FILES[$this->name_file]['name'];
+ //Check the image for delete.
+ //This field is used only for a row
+ $old_image=Webmodel::$model[$this->name_model]->select_a_row_where(array($this->name_component), 1)[$this->name_component];
+
+ }
+
+ if(isset($_FILES[$file_name]['tmp_name']))
+ {
- $manager = new ImageManager(array('driver' => $this->driver));
-
- if($image=$manager->make($_FILES[$this->name_file]['tmp_name'])!=false)
- {
-
- //$with=
-
- //if(make('foo.jpg')->resize(300, 200)->save('bar.jpg');
-
- if($this->thumb)
- {
-
- $base_name_image=basename($name_image);
-
- foreach($this->img_width as $prefix => $width)
- {
-
- $image->reset();
-
- //In nexts versions, save in tmp and move with ftp copy.
-
- if(!$image->fit($width)->encode('jpg', $this->quality_jpeg)->save($this->path.'/'.$prefix.'_'.$base_name_image.'.jpg'))
- {
-
- $this->std_error=I18n::lang('common', 'cannot_save_images', 'Cannot save images, please, check permissions');
-
- }
-
- }
-
- }
-
-
- if($this->update)
- {
-
- //Check the image for delete.
- $query=$model[$this->name_model]->select(array($this->name_component), 1);
-
- while(list($old_image)=$model[$this->name_model]->fetch_row($query))
- {
-
- if(!@unlink($this->path.'/'.$old_image))
- {
- $this->std_error=I18n::lang('common', 'cannot_delete_old_image', 'Cannot delete old images, please, check permissions');
- }
-
- $base_old_image=basename($old_image);
-
- foreach($this->img_width as $prefix => $width)
- {
-
- if(!@unlink($this->path.'/'.$prefix.'_'.$base_old_image))
- {
- $this->std_error=I18n::lang('common', 'cannot_delete_old_image', 'Cannot delete old thumb images, please, check permissions');
- }
-
- }
-
- }
+ if(trim($_FILES[$file_name]['tmp_name'])!=='')
+ {
- }
-
- //Copy the image
-
- $image->reset();
-
- if($image->save($this->path.'/'.$prefix.'_'.$image_name))
- {
+
+ $name_image=$_FILES[$file_name]['name'];
+
+ $manager = new ImageManager(array('driver' => $this->driver));
+
+ if( ($image=$manager->make($_FILES[$file_name]['tmp_name']))!=false)
+ {
+
+ if($old_image!='')
+ {
+
+ if(!@unlink($this->path.'/'.$old_image))
+ {
+ $this->std_error=I18n::lang('common', 'cannot_delete_old_image', 'Cannot delete old images, please, check permissions');
+ }
+
+ $base_old_image=basename($old_image);
+
+ foreach($this->img_width as $prefix => $width)
+ {
+
+ if(!@unlink($this->path.'/'.$prefix.'_'.$base_old_image))
+ {
+ $this->std_error=I18n::lang('common', 'cannot_delete_old_image', 'Cannot delete old thumb images, please, check permissions');
+ }
+
+ }
+ }
+
+ $image->backup();
+
+ //$with=
+
+ //if(make('foo.jpg')->resize(300, 200)->save('bar.jpg');
+
+
+ if($this->thumb)
+ {
+
+ $base_name_image=basename($name_image);
+
+ $file_extension=pathinfo($base_name_image, PATHINFO_EXTENSION);
+
+ $base_name_image=str_replace('.'.$file_extension, '', $base_name_image);
+
+ foreach($this->img_width as $prefix => $width)
+ {
+
+ $image->reset();
+
+ //In nexts versions, save in tmp and move with ftp copy.
+
+ if(!$image->fit($width)->encode('jpg', $this->quality_jpeg)->save($this->path.'/'.$prefix.'_'.$base_name_image.'.jpg'))
+ {
+
+ $this->std_error=I18n::lang('common', 'cannot_save_images', 'Cannot save images. Please, check permissions');
+
+ }
+
+ }
+
+ }
+
+ //Copy the image
+
+ $image->reset();
+
+ if(!$image->save($this->path.'/'.$name_image))
+ {
- $this->std_error=I18n::lang('common', 'cannot_save_images', 'Cannot save images, please, check permissions');
-
- return false;
+ $this->std_error=I18n::lang('common', 'cannot_save_images', 'Cannot save images, please, check permissions');
+
+ return '';
+
+ }
+
+ return $name_image;
}
+ else
+ {
- return $image_name;
+ $this->std_error=I18n::lang('common', 'no_valid_image', 'This image is wrong');
+ return '';
+
+ }
}
else
{
- $this->std_error=I18n::lang('common', 'no_valid_image', 'This image is wrong');
-
- return false;
+ return $old_image;
}
-
}
$this->std_error=I18n::lang('common', 'no_image_found', 'No image uploaded, check enctype form');
- return false;
-
- /*
-
- $file=$this->name_file;
- $image=basename($image);
-
- settype($_POST['delete_'.$file], 'integer');
-
- if($_POST['delete_'.$file]==1)
- {
-
- //Delete old_image
-
- $image_file=Utils::form_text($_POST[$file]);
-
- if($image_file!='')
- {
-
- @unlink($this->path.'/'.$image_file);
-
- foreach($this->img_width as $key => $value)
- {
-
- @unlink($this->path.'/'.$key.'_'.$image_file);
-
- }
-
- $image='';
-
- }
-
- }
-
- if(isset($_FILES[$file]['tmp_name']))
- {
-
- if($_FILES[$file]['tmp_name']!='')
- {
-
-
- $arr_image=getimagesize($_FILES[$file]['tmp_name']);
-
- $_FILES[$file]['name']=Utils::slugify(Utils::form_text($_FILES[$file]['name']));
-
- if($this->prefix_id==1)
- {
-
- $func_token=$this->func_token;
-
- $_FILES[$file]['name']=$func_token().'_'.$_FILES[$file]['name'];
-
- }
-
- $this->value=$_FILES[$file]['name'];
-
- //Check size
-
- if($this->min_size[0]>0 && $this->min_size[1]>0)
- {
-
- if($arr_image[0]<$this->min_size[0] || $arr_image[1]<$this->min_size[1])
- {
-
- $this->std_error=I18n::lang('common', 'image_size_is_not_correct', 'Image size is wrong').'
'.I18n::lang('common', 'min_size', 'Minimal size').': '.$this->min_size[0].'x'.$this->min_size[1];
-
- $this->value='';
- return '';
-
-
- }
-
- }
-
- //Delete other image if exists..
-
- if($image!='')
- {
-
- unlink($this->path.'/'.$image);
-
- }
-
- //gif 1
- //jpg 2
- //png 3
- //Only gifs y pngs...
-
- //Need checking gd support...
-
- $func_image[1]='imagecreatefromgif';
- $func_image[2]='imagecreatefromjpeg';
- $func_image[3]='imagecreatefrompng';
-
- if($arr_image[2]==1 || $arr_image[2]==2 || $arr_image[2]==3)
- {
-
- $image_func_create='imagejpeg';
-
- switch($arr_image[2])
- {
-
- case 1:
-
- //$_FILES[$file]['name']=str_replace('.gif', '.jpg', $_FILES[$file]['name']);
- $image_func_create='imagegif';
-
- break;
-
- case 3:
-
- //$_FILES[$file]['name']=str_replace('.png', '.jpg', $_FILES[$file]['name']);
- $image_func_create='imagepng';
- //Make conversion to png scale
- $this->quality_jpeg=floor($this->quality_jpeg/10);
-
- if($this->quality_jpeg>9)
- {
-
- $this->quality_jpeg=9;
-
- }
-
- break;
-
- }
-
- $move_file_func=$this->move_file_func;
-
-
- if( $move_file_func ( $_FILES[$file]['tmp_name'] , $this->path.'/'.$_FILES[$file]['name'] ))
- {
-
- //Make jpeg.
-
- $func_final=$func_image[$arr_image[2]];
-
- $img = $func_final($this->path.'/'.$_FILES[$file]['name']);
-
- //imagejpeg ( $img, $this->path.'/'.$_FILES[$file]['name'], $this->quality_jpeg );
-
- //Reduce size for default if $this->img_width['']
-
- if(isset($this->img_width['']))
- {
- if($arr_image[0]>$this->img_width[''])
- {
- $width=$this->img_width[''];
-
- $ratio = ($arr_image[0] / $width);
- $height = round($arr_image[1] / $ratio);
-
- $thumb = imagecreatetruecolor($width, $height);
-
- imagecopyresampled ($thumb, $img, 0, 0, 0, 0, $width, $height, $arr_image[0], $arr_image[1]);
-
- $image_func_create ( $thumb, $this->path.'/'.$_FILES[$file]['name'], $this->quality_jpeg );
-
- }
-
- unset($this->img_width['']);
- }
-
- //Make thumb if specific...
- if($this->thumb==1)
- {
-
- //Convert to jpeg.
-
- foreach($this->img_width as $name_width => $width)
- {
-
- $ratio = ($arr_image[0] / $width);
- $height = round($arr_image[1] / $ratio);
-
- if(isset($this->img_minimal_height[$name_width]))
- {
-
- if($height<$this->img_minimal_height[$name_width])
- {
-
- //Need recalculate the adecuate width and height.
-
- $height=$this->img_minimal_height[$name_width];
-
- $ratio=($arr_image[1] / $height);
-
- $width=round($arr_image[0]/$ratio);
-
- //$width=
-
- }
-
- }
-
- $thumb = imagecreatetruecolor($width, $height);
-
- imagecopyresampled ($thumb, $img, 0, 0, 0, 0, $width, $height, $arr_image[0], $arr_image[1]);
-
- $image_func_create ( $thumb, $this->path.'/'.$name_width.'_'.$_FILES[$file]['name'], $this->quality_jpeg );
- ;
- //imagepng ( resource $image [, string $filename [, int $quality [, int $filters ]]] )
-
- }
-
- }
-
- //unlink($_FILES[$file]['tmp_name']);
-
- //Unlink if exists image
-
- if(isset($_POST[$file]))
- {
-
- if($_POST[$file]!='')
- {
- $image_file=Utils::form_text($_POST[$file]);
-
- if($image_file!='')
- {
-
- @unlink($this->path.'/'.$image_file);
-
- foreach($this->img_width as $key => $value)
- {
-
- @unlink($this->path.'/'.$key.'_'.$image_file);
-
- }
-
- $image='';
-
- }
-
- }
-
- }
-
- return $_FILES[$file]['name'];
-
- //return $this->path.'/'.$_FILES[$file]['name'];
-
- }
- else
- {
-
- $this->std_error=I18n::lang('common', 'error_cannot_upload_this_image_to_the_server', 'Error: Cannot upload this image to the server');
-
- if(DEBUG==1)
- {
-
- $this->std_error.=' Image origin '.$_FILES[$file]['tmp_name'].' in this path '.$this->path;
-
- }
-
- return '';
-
- }
-
-
- }
- else
- {
-
- $this->std_error.=I18n::lang('error_model', 'img_format_error', 'Img format error, only accept gif, jpg and png formats');
-
- }
-
- }
- else if($image!='')
- {
-
- return $image;
-
- }
-
-
- }
- else if($image!=='')
- {
-
-
- if(file_exists($this->path.'/'.$image))
- {
-
- $this->value=$this->path.'/'.$image;
- return $image;
-
- }
- else
- {
-
- $this->std_error=I18n::lang('error_model', 'check_error_enctype_for_upload_file', 'Please, check enctype form of file form');
- return '';
-
- }
-
-
-
- }
- else
- {
-
- $this->std_error=I18n::lang('error_model', 'check_error_enctype_for_upload_file', 'Please, check enctype form of file form');
-
- }
- */
-
- $this->value='';
- return '';
+ return '';
}
@@ -481,15 +194,13 @@ class ImageField extends PhangoField {
}
- function process_delete_field($model, $name_field, $conditions)
+ function process_delete_field($model, $name_field)
{
-
-
//die;
- $query=$model->select($conditions, array($name_field));
+ $query=$model->select(array($name_field));
- while(list($image_name)=webtsys_fetch_row($query))
+ while(list($image_name)=$model->fetch_row($query))
{
if( file_exists($this->path.'/'.$image_name) && !is_dir($this->path.'/'.$image_name) )
@@ -570,6 +281,14 @@ class ImageField extends PhangoField {
return '
';
}
+
+ function get_parameters_default()
+ {
+
+ $this->form_loaded->file_url=$this->url_path;
+
+
+ }
}
diff --git a/src/Forms/FileForm.php b/src/Forms/FileForm.php
index e306138..6485686 100644
--- a/src/Forms/FileForm.php
+++ b/src/Forms/FileForm.php
@@ -3,6 +3,7 @@
namespace PhangoApp\PhaModels\Forms;
use PhangoApp\PhaModels\Forms\BaseForm;
+use PhangoApp\PhaUtils\Utils;
/**
* Basic class for create forms
@@ -17,8 +18,17 @@ class FileForm extends BaseForm{
$this->type='file';
$this->enctype=1;
+ $this->file_url='';
}
+
+ public function form()
+ {
+
+ return ' '.Utils::form_text($this->default_value).'';
+
+ }
+
}