第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定
已解決430363個(gè)問(wèn)題,去搜搜看,總會(huì)有你想問(wèn)的

在 PHP 中上傳不會(huì)創(chuàng)建臨時(shí)文件

在 PHP 中上傳不會(huì)創(chuàng)建臨時(shí)文件

PHP
慕田峪9158850 2023-12-15 15:05:58
我正在嘗試通過(guò)上傳表單將圖像發(fā)送到 php 腳本,但該文件沒(méi)有顯示在我的臨時(shí)文件夾中。我嘗試搜索錯(cuò)誤并找到了此答案。多次檢查每個(gè)步驟后,我仍然發(fā)現(xiàn)自己沒(méi)有上傳文件...表格 :<form id="addImageForm" action="functions/add_image.php" method="POST" enctype="multipart/form-data">  <label for="articleImage">Select a file:</label>  <input type="file" name="articleImage" id="articleImage">  <input type="submit" class="btn btn-success" value="Submit"></form>add_image.php 腳本:<?php/* Checking request parameters */if(!isset($_FILES['articleImage']) || empty($_FILES['articleImage'])) {    echo "Error : the file is missing";    die();}/* Checking upload errors */if($_FILES['articleImage']['error'] != UPLOAD_ERR_OK) {    echo "Error : ".$_FILES['articleImage']['error'];    die();}/* Checking file size */if($_FILES['articleImage']['size'] == 0) {    echo "Error : the file is empty";    die();}/* Checking file has been uploaded to tmp */if(is_uploaded_file($_FILES['articleImage']['tmp_name'])) {    echo "Error : the file didn't upload";    die();}/* Checking file doesn't already exist */$imagePath = "img/articles/".$_FILES['articleImage']['name'];if(file_exists($imagePath)) {    echo "Error : the filename is already taken";    die();}/* Writing image */if(!move_uploaded_file($_FILES['articleImage']['tmp_name'], $imagePath)) {    echo "Error : the file coundn't be written";    die();}echo 'Success';die();?>請(qǐng)求已正確發(fā)送:-----------------------------45933353531894573431775954628Content-Disposition: form-data; name="articleImage"; filename="my_file.png"Content-Type: image/png[image content]-----------------------------45933353531894573431775954628--但我仍然收到“文件未上傳”的消息錯(cuò)誤...正如我之前提到的,我確實(shí)檢查了我的 php conf(使用 /tmp 作為 upload_tmp_dir 編輯了正確的 php.ini 文件并將上傳限制設(shè)置為 100M),并且 /tmp 上有 777 chmod。我缺少什么?
查看完整描述

1 回答

?
嚕嚕噠

TA貢獻(xiàn)1784條經(jīng)驗(yàn) 獲得超7個(gè)贊

我已經(jīng)復(fù)制并以某種方式測(cè)試了您的代碼。您不需要執(zhí)行 is_uploaded_file 調(diào)用,因?yàn)檫@些檢查是在 move_uploaded_file 函數(shù)中進(jìn)行的(https://www.php.net/manual/en/function.is-uploaded- file.php#113766)。另請(qǐng)檢查存儲(chǔ)圖像的目錄是否存在。


<?php


/* Directory where uploaded images will be placed */

$imageDir = 'img/articles';


/* Checking request parameters */

if (!isset($_FILES['articleImage']) || empty($_FILES['articleImage'])) {

    echo "Error : the file is missing";

    die();

}


/* Checking upload errors */

if ($_FILES['articleImage']['error'] != UPLOAD_ERR_OK) {

    echo "Error : " . $_FILES['articleImage']['error'];

    die();

}


/* Checking file size */

if ($_FILES['articleImage']['size'] == 0) {

    echo "Error : the file is empty";

    die();

}

/* Checking if directory exists */

if (!is_dir($imageDir)) {

    echo 'Image directory does not exist';

    die();

}


/* Checking file doesn't already exist */

$imagePath = $imageDir . $_FILES['articleImage']['name'];

if (file_exists($imagePath)) {

    echo "Error : the filename is already taken";

    die();

}


/* Writing image */

if (!move_uploaded_file($_FILES['articleImage']['tmp_name'], $imagePath)) {

    echo "Error : the file coundn't be written";

    die();

}


echo 'Success';

die();


查看完整回答
反對(duì) 回復(fù) 2023-12-15
  • 1 回答
  • 0 關(guān)注
  • 203 瀏覽

添加回答

舉報(bào)

0/150
提交
取消
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)