我目前正在開發(fā)驗(yàn)證碼系統(tǒng)。為此,我正在創(chuàng)建帶有一些基本數(shù)學(xué)問題的隨機(jī)圖片。用戶在提交表單之前必須給出正確的答案。這是代碼:<?php function randExer() { //Creating random (simple) math problem $arr = array("zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine", "ten"); $item1 = $arr[array_rand($arr)]; $item2 = $arr[array_rand($arr)]; $random = $item1 . " + " . $item2; //Saving created math problem for later file_put_contents("../sites/exercise.txt", $random); //Creates a black picture with width=200 and height = 50 $img = imagecreatetruecolor(200, 50); //uses RGB-values to create a useable color $white = imagecolorallocate($img, 255, 255, 255); $silver = imagecolorallocate($img, 192, 192, 192); //Adds random lines to the images for($i = 0; $i < 5; $i++) { imagesetthickness($img, rand(1, 3)); $x1 = rand(0, 100); $y1 = rand(0, 25); $x2 = $x1 + rand(0, 100); $y2 = $y1 + rand(0, 25); imageline($img, $x1, $x2, $x2, $y2, $silver); } //Adds white-colored text $var = imagestring($img, 5, 18, 18, $random . " = ?", $white); $rotate = imagerotate($img, 10, 0); //Save image imagejpeg($rotate, "../sites/exercise.png", -1); };?>正如我在代碼審查中的問題的評(píng)論中所指出的,如果超過一個(gè),系統(tǒng)將無法工作客戶端同時(shí)使用表單,因?yàn)閳D像將保存在同一個(gè)地方。如何在不使用不同文件名保存每張圖片的情況下解決這個(gè)問題(我真的不希望我的服務(wù)器充滿圖像)?
同時(shí)為多個(gè)用戶保存文件
婷婷同學(xué)_
2023-12-15 16:10:21