0

I'm trying to upload a photo using the following code. Suppose I'm uploading "abc.gif". It uploads in the proper directory as "abc.jpg". But my question is does the file type actually change?

$file_name = $_FILES['input_name']['name'];
$file_tmp =$_FILES['input_name']['tmp_name'];
move_uploaded_file($file_tmp, "abc.jpg");

This piece of code works perfectly while uploading. But while making a resized copy of this abc.jpg using—

imagecreatefromjpg("abc.jpg") & imagejpeg() 

—it shows a black screen.

When I move the file using the extension .jpg, does the file type actually change? Why does this problem occur?

Debabrata Roy
  • 31
  • 1
  • 1
  • 5
  • 1
    Just giving a file another name does _not_ magically change its content. – arkascha Mar 11 '17 at 11:37
  • This might be a good starting point to read for you: http://stackoverflow.com/questions/28154179/php-imagick-gif-to-jpg-background – arkascha Mar 11 '17 at 11:44
  • but after moving the file, i checked the properties of the moved file, it says jpg. and orginal file says gif. I'm actually confused here – Debabrata Roy Mar 11 '17 at 11:56
  • You do understand that the file-extension says absolutely nothing about what a file actually is, right? – junkfoodjunkie Mar 11 '17 at 12:00
  • Depending on what utility you use to determine the type of a file you may very well get a wrong answer. – arkascha Mar 11 '17 at 12:02
  • You need to implement a simple type conversion, not just a renaming if you actually want to change the files content. That is why I gave you the link to the question in a comment above. In that questions answer a simple working implementation of what you need is shown. – arkascha Mar 11 '17 at 12:05

1 Answers1

0

Please verify the your imagecreatefromjpg("abc.jpg") & imagejpeg() function work correctly, you say file move successfully and display correctly so issue in the this image operation function which convert image into black image.

Thanks.

kishor soneji
  • 795
  • 1
  • 9
  • 16
  • The OP never even _tries_ to convert the image type. So certainly no conversion function or utility will be touched by that code. – arkascha Mar 11 '17 at 11:45
  • Some time parameter are not pass correctly so image conversion not done properly result is its convert into black image. – kishor soneji Mar 11 '17 at 11:48
  • I think i was wrong, i read this lines "This piece of code works perfectly while uploading. but while making a resized copy of this abc.jpg using imagecreatefromjpg("abc.jpg") & imagejpeg() it shows a black screen. So can you tell me when i move the file using the extension .jpg, does the file type actually changes??" – kishor soneji Mar 11 '17 at 11:52
  • No, the files content is not magically changed just because you change its name. – arkascha Mar 11 '17 at 12:04