好吧,我在这个领域是全新的,并通过一些教程,我发现在PHP上传文件时,它将它们存储在一个临时位置.
$file_temp=$_FILES['file']['tmp_name'];
$file_loc="Upload".$file_name;
move_uploaded_files($file_temp,$file_loc);
Run Code Online (Sandbox Code Playgroud)
现在为什么PHP不允许直接将文件上传到所需的位置?为什么它们存储在扩展名为.tmp的临时位置,我们从这个策略中获得了什么好处?
我正在使用此代码创建水印。
$image = '1.jpg';
$overlay = 'stamp.png';
$opacity = "20";
if (!file_exists($image)) {
die("Image does not exist.");
}
// Set offset from bottom-right corner
$w_offset = 0;
$h_offset = 100;
$extension = strtolower(substr($image, strrpos($image, ".") + 1));
// Load image from file
switch ($extension)
{
case 'jpg':
$background = imagecreatefromjpeg($image);
break;
case 'jpeg':
$background = imagecreatefromjpeg($image);
break;
case 'png':
$background = imagecreatefrompng($image);
break;
case 'gif':
$background = imagecreatefromgif($image);
break;
default:
die("Image is of unsupported type.");
}
// Find base image …Run Code Online (Sandbox Code Playgroud)