Jump to content

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.