I am having a problem in getting a image uploading to the server (first I convert it to .png and resize it):
In functions.php
function imageUploadedResize($source, $target,$nWidth, $nHeight)
{
$sourceImg = Imagecreatefromstring(file_get_contents($source));
if ($sourceImg === false)
{
return false;
}
$width = imagesx($sourceImg);
$height = imagesy($sourceImg);
$targetImg = imagecreatetruecolor($nWidth, $nHeight);
imagecopyresized($targetImg, $sourceImg, 0, 0, 0, 0, $nWidth,$nHeight,$width, $height);
imagedestroy($sourceImg);
imagepng($targetImg, $target);
imagedestroy($targetImg);
}
In uploadtoServer.php
if(isset($_POST["fileToUpload"]))
{
$target_dir = "img/data/";
$fn = $_FILES['fileToUpload']['tmp_name'];
$newFileName = mysqli_insert_id($link).".png";
header('Content-type: image/png');
imageUploadedResize($fn, $target_dir.$newFileName, 45,60);
}
If I change $fn to a static image like "https://pbs.twimg.com/profile_images/54789364/JPG-logo-highres.jpg" it works so I guess I am having a problem in $fn. Any thoughts what can it be?