Jump to content

Can I use $_Files twice for uploading image?


bugzy

Recommended Posts

I thought it would be simple but it seemed like it's complicated.

 

I want to use the $_FILE twice so that I could have two copy of the image with different names..

 

I'm doing it like this

 

<?php


//resizing image here

$ext = ".". pathinfo($_FILES['uploaded_image']['name'], PATHINFO_EXTENSION);
$target_path = "../images_item/";

$filename1 = $target_path . $last_id."_medium".$ext;
$filename2 = $target_path . $last_id."_large".$ext;


$copied1 = move_uploaded_file($_FILES['uploaded_image']['tmp_name'], $filename1);

$copied2 = move_uploaded_file($_FILES['uploaded_image']['tmp_name'], $filename2);


?>

 

 

$_FILES is coming from an html form.

 

Tried it but it only upload once..

 

Any idea guys?  :shrug:

 

Your problem has nothing to do with $_FILES,  it has to do with move_uploaded_file.  The purpose of that function is to move a file from what is essentially php's temporary holding location, and move it to a location of your choosing.  Once you've moved it, it is no longer at the temporary holding location.

 

Based on what your code is trying to do, you should do the move_uploaded_file call.  Then use copy to make the copy of the moved file and place it in the same location.

I tried this

 

<?php

$filename1 = $target_path . $last_id."_small".$ext;
			$filename2 = $target_path . $last_id."_medium".$ext;
			$filename3 = $target_path . $last_id."_large".$ext;

			$copied1 = copy($_FILES['uploaded_image']['tmp_name'], $filename1);

			$copied2 = copy($_FILES['uploaded_image']['tmp_name'], $filename2);

			$copied3 = move_uploaded_file($_FILES['uploaded_image']['tmp_name'], $filename3);


?>

 

 

and it works... but I'm concern if using "copy" is the proper way to this because I might have some issue..

 

Do you guys think it's fine?

Like this:

 

$small_image = $target_path . $last_id."_small".$ext;
$medium_image = $target_path . $last_id."_medium".$ext;
$large_image = $target_path . $last_id."_large".$ext;

$large_image_created = move_uploaded_file($_FILES['uploaded_image']['tmp_name'], $large_image);
$medium_image_created = copy($large_image, $medium_image);
$small_image_created = copy($medium_image, $small_image);

 

move and copy do not resize images so if you don't have any resize code in there _small and _medium are all going to be the same size as _large.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.