使用以下代码可以有人向我解释如何在上传过程中将图像文件重命名为misc名称?
这是我正在使用的.
uploader.php
<?php
include($_SERVER['DOCUMENT_ROOT'] . "/connections/dbconnect.php");
$dataType = mysql_real_escape_string($_POST["dataType"]);
$title = mysql_real_escape_string($_POST["title"]);
$fileName = basename($_FILES["image"]["name"]);
$target_path = ($_SERVER['DOCUMENT_ROOT'] . "/images/gallery/".$fileName);
if (file_exists($target_path))
{
echo "An image with that file name already exists.";
}
elseif (move_uploaded_file($_FILES["image"]["tmp_name"], $target_path))
{
// The file is in the images/gallery folder. Insert record into database by
// executing the following query:
$sql="INSERT INTO images (data_type, title, file_name)"."VALUES('$dataType','$title','$fileName')";
$retval = mysql_query($sql);
echo "The image was successfully uploaded and added to the gallery :) <a href='index.php'>Add another …Run Code Online (Sandbox Code Playgroud) 我得到了这个厨房约占我想要它的65%.我想知道是否有人可以查看以下代码并告诉我如何将多个图像上传到我的图库.
这是代码.
简单的管理表单代码:
<form enctype="multipart/form-data" action="uploader.php" method="POST">
Category: <select class="text" name="dataType[]">
<option value="treeremoval" selected="selected">treeremoval</option>
<option value="treetrimming" >treetrimming</option>
<option value="treebracing" >treebracing</option>
<option value="stumpgrinding" >stumpgrinding</option>
<option value="firewood" >firewood</option>
<option value="cleanup" >cleanup</option>
</select>
<br /><br />
Caption: <input type="text" name="title[]">
<br /><br />
Image to upload: <input type="file" name="image[]" />
<br /><br />
Category: <select class="text" name="dataType[]">
<option value="treeremoval" selected="selected">treeremoval</option>
<option value="treetrimming" >treetrimming</option>
<option value="treebracing" >treebracing</option>
<option value="stumpgrinding" >stumpgrinding</option>
<option value="firewood" >firewood</option>
<option value="cleanup" >cleanup</option>
</select>
<br /><br />
Caption: <input type="text" name="title[]"> …Run Code Online (Sandbox Code Playgroud) 我有一个赞助应用程序,并尝试在用户赞助孩子后将赞助孩子和用户添加到数据透视表中。
我为赞助者孩子和用户创建了一个数据透视表。在第一个事务中,表中的关系是正确的,但如果用户返回并再次赞助孩子的第二个或第三个插槽,我会收到以下错误:
SQLSTATE[23000]:违反完整性约束:1062 键“PRIMARY”的重复条目“1-1”(23000)
kid_user数据透视表:
public function up()
{
Schema::create('kid_user', function (Blueprint $table) {
$table->integer('kid_id')->unsigned()->index();
$table->foreign('kid_id')->references('id')->on('kids')->onDelete('cascade');
$table->integer('user_id')->unsigned()->index();
$table->foreign('user_id')->references('id')->on('users')->onDelete('cascade');
$table->primary(['kid_id', 'user_id']);
$table->timestamps();
});
}
Run Code Online (Sandbox Code Playgroud)
儿童模型:
public function users() {
return $this->belongsToMany(User::class)->withTimestamps();
}
Run Code Online (Sandbox Code Playgroud)
用户型号:
public function kids(){
return $this->belongsToMany(Kid::class)->withTimestamps();
}
Run Code Online (Sandbox Code Playgroud)
用这一行连接到我的控制器中:
$cin = $request->cin;
$kidid = $request->kidid;
$kids = DB::table('kids')->where('cin', $cin)->increment('sponsors_received');
$user = Auth::user();
$user->kids()->attach($kidid);
//$user->kids()->sync($kidid);
;
Run Code Online (Sandbox Code Playgroud)
我目前得到的:
+--------------------+
| kid_user table |
+--------------------+
| *kid_id | *user_id | * = Primary Key
+---------+----------+
| …Run Code Online (Sandbox Code Playgroud) 我创建了一个在后台处理 PDF 的作业。工作完成后,我想向 Auth 用户发送一封电子邮件,其中包含下载新生成的 PDF 的链接。
这是我目前正在做的事情。
控制器:
public function haitiKidPdfAll(){
$pdfUser = User::find(Auth::user()->id);
$haitiKids = Kid::
whereRaw('sponsors_received < sponsors_needed')
->where('current_country', 'Haiti')
->orderBy('sponsors_received', 'ASC')
->get();
ProcessPdfHaiti::dispatch($haitiKids,$pdfUser);
return back()->with('info','This will take a couple minutes. I\'ll email you when it\'s completed.');
Run Code Online (Sandbox Code Playgroud)
流程Pdf海地工作:
此处出现错误:未定义的变量:pdfUser {“异常”:“[对象](ErrorException(代码:0):未定义的变量:第53行的pdfUser。在
$pdfUserEmail = $pdfUser->email;下面的代码中。
class ProcessPdfHaiti implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;
public $haitiKids;
public $pdfUser;
public function __construct($haitiKids,$pdfUser)
{
$this->haitiKids = $haitiKids;
$this->pdfUser = $pdfUser;
}
public function handle()
{
...PDF Query Stuff
$pdfUserEmail …Run Code Online (Sandbox Code Playgroud)