我正在尝试制作一个上传功能,为内存中上传的每个文件添加水印,然后将文件保存到特定文件夹。但是,我无法让代码的水印部分工作。我确信上传功能可以在没有添加水印代码的情况下工作。我相信错误一定是水印代码将临时文件“传输”到将文件移动到硬盘驱动器的代码的地方。我该如何解决这个问题?
代码如下:
foreach($_FILES['files']['tmp_name'] as $key => $tmp_name ){
$file_name = $_FILES['files']['name'][$key];
$file_size =$_FILES['files']['size'][$key];
$file_tmp =$_FILES['files']['tmp_name'][$key];
//$file_type=$_FILES['files']['type'][$key];
//if($file_size > 2097152){
//$errors[]='File size must be less than 2 MB';
//}
// echo '<img src="../images/watermark.gif">';
$q = "INSERT INTO media (file_name, album_id, file_size) VALUES ('$file_name','$album_id', '$file_size')";
$r = mysqli_query ($dbc, $q);
$desired_dir = '../../customers/' . $customerFolder . '/';
// load the watermark and the photo
$watermark = imagecreatefromgif('../images/watermark.gif');
$photo = imagecreatefromjpeg($file_tmp);
// center watermark on the photo
$wx = imagesx($photo)/2 - imagesx($watermark)/2;
$wy = imagesy($photo)/2 - imagesy($watermark)/2;
imagecopy($photo, $watermark, $wx, $wy, 0, 0, imagesx($watermark), imagesy($watermark));
if(empty($errors)==true){
move_uploaded_file($photo,"$desired_dir".$file_name);
//mysql_query($q);
}else{
print_r($errors);
}
}