after long hours snipping code and placing in respective places in my own multi file uploader code ive run into an error wihout any reason to my knowledge the code bellow is what im using
<?php
ini_set("error_reporting", 1);
if(isset($_POST['btnSubmit']))
{
for ($i = 0; $i < count($_FILES['files']['name']); $i++)
{
if ($_FILES["files"]["size"][$i] < 1000000000) // Check File size (Allow 1000MB)
{
$temp = $_FILES["files"]["tmp_name"][$i];
$name = $_FILES["files"]["name"][$i];
$targetFilePath = 'images/thumbs/'.$name;
$watermarkImagePath = 'watermark.png';
$statusMsg = '';
if(move_uploaded_file($_FILES["file"]["tmp_name"][$i], $targetFilePath)){
// Load the stamp and the photo to apply the watermark to
$watermarkImg = imagecreatefrompng($watermarkImagePath);
switch($fileType){
case 'jpg':
$im = imagecreatefromjpeg($targetFilePath);
break;
case 'jpeg':
$im = imagecreatefromjpeg($targetFilePath);
break;
case 'png':
$im = imagecreatefrompng($targetFilePath);
break;
default:
$im = imagecreatefromjpeg($targetFilePath);
}
}
// Set the margins for the watermark
$marge_right = 10;
$marge_bottom = 10;
// Get the height/width of the watermark image
$sx = imagesx($watermarkImg);
$sy = imagesy($watermarkImg);
// Copy the watermark image onto our photo using the margin offsets and
// the photo width to calculate the positioning of the watermark.
imagecopy($im, $watermarkImg, imagesx($im) - $sx - $marge_right, imagesy($im) - $sy - $marge_bottom, 0, 0, imagesx($watermarkImg), imagesy($watermarkImg))>debug.log;
// Save image and free memory
imagepng($im, $targetFilePath);
$old = $targetFilePath;
$new = "images/fulls/".$name;
echo '<br/>img:'.$im.' <br/>target:'.$targetFilePath.' <br/>name:'.$name.' <br/>old:'.$old.' <br/>new:'.$new.'<br/>';
copy($old, $new) or die("Unable to copy $old to $new.");
imagedestroy($im);
if(file_exists($targetFilePath)){
$statusMsg = "The image with watermark has been uploaded successfully.";
}else{
$statusMsg = "Image upload failed, please try again.";
}
// Display status message
echo $statusMsg;
if(empty($temp))
{
break;
}
if($i == 0){ $err = "<span style='color:lime;'>Files uploaded successfully</span>"; $cls = "success"; }
//move_uploaded_file($temp,"images/thumbs/".$name);
//$old = "images/thumbs/".$name;
//$new = "images/fulls/".$name;
//copy($old, $new) or die("Unable to copy $old to $new.");
}
else
{
$err = "File size is more than 1000MB";
$cls = "danger";
}
}
}
?>
the form and html is extensive but operable so i wont include that the php is where the error is coming from i fugure theres an issue with my code stitching womehwere but the return is either an image without my watermark or the or die
error in the copy snippet returning the could not copy file x to location n
hopefully this is a silly simple fix but to my limited knowledge im not sure what ive done wrong