bugzy Posted July 26, 2012 Share Posted July 26, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/266260-can-i-use-_files-twice-for-uploading-image/ Share on other sites More sharing options...
gizmola Posted July 26, 2012 Share Posted July 26, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266260-can-i-use-_files-twice-for-uploading-image/#findComment-1364477 Share on other sites More sharing options...
bugzy Posted July 26, 2012 Author Share Posted July 26, 2012 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? Quote Link to comment https://forums.phpfreaks.com/topic/266260-can-i-use-_files-twice-for-uploading-image/#findComment-1364478 Share on other sites More sharing options...
Barand Posted July 26, 2012 Share Posted July 26, 2012 Move it once as the large image. Create resized images from that to get the medium and small versions. Quote Link to comment https://forums.phpfreaks.com/topic/266260-can-i-use-_files-twice-for-uploading-image/#findComment-1364510 Share on other sites More sharing options...
gizmola Posted July 27, 2012 Share Posted July 27, 2012 bugzy: You should call move_uploaded_file first. Then as Barand suggests, use that copy with its persistent location/name that you assigned, as the basis for making your thumbnail versions. Quote Link to comment https://forums.phpfreaks.com/topic/266260-can-i-use-_files-twice-for-uploading-image/#findComment-1364926 Share on other sites More sharing options...
ignace Posted July 28, 2012 Share Posted July 28, 2012 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. Quote Link to comment https://forums.phpfreaks.com/topic/266260-can-i-use-_files-twice-for-uploading-image/#findComment-1365021 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.