Question

I've got this code and I need copy the two images 'original' and 'tmp_image' in folder images/app.

How i can move this pictures? :

I've tried this but only moves picture 'original':

move_uploaded_file("images/app/".$_FILES["imagen"]["tmp_name"],"images/app/".$_FILES["imagen"]["name"]);

 function resize($target,$new,$w,$h,$type){
   list($wo,$ho)=getimagesize($target);
    if($type=="image/jpeg"){
     $nen = imagecreatefromjpeg($target);
    }elseif($type=="image/gif"){
     $nen = imagecreatefromgif($target);
    }elseif($type=="image/png"){
     $nen = imagecreatefrompng($target);
    }
      $chen = imagecreatetruecolor($w,$h);
      imagecopyresampled($chen,$nen,0,0,0,0,$w,$h,$wo,$ho);
      imagejpeg($chen,$new,80);
                                         }

And

move_uploaded_file($_FILES["imagen"]["tmp_name"],$_FILES["imagen"]["name"]);
    $meter = "http://server/prueba/images/app/" . $_FILES["imagen"]["name"];
    $target = $_FILES["imagen"]["name"];
    $ssql = "insert into ofertas (imagen) values ('" . $meter . "')";
            $new = "resize_".$target;
            $type = $_FILES['imagen']['type'];
            $w = 80;
            $h = 80;
            resize($target,$new,$w,$h,$type);

Thanks all!!

Was it helpful?

Solution

Your explanation of a problem is a bit hard to understand. If I got it right, below is the answer.

If you are moving uploaded file to new location and then resizing it - it is overwritten. Try changing target name and copy file to target name. For example

$target = $_FILES["imagen"]["name"];

Change to

 $target = 'thumb_'.$_FILES["imagen"]["name"];
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top