任何人都可以幫助我解決這個文件上傳在php中的問題。我在線獲取未定義的索引!代碼分爲兩個獨立的文件。我嘗試了幾個代碼,仍然沒有工作。請幫忙。謝謝大家。 HTML文件上傳文件在PHP不工作
<form role="form" name="uploadPro" id="uploadPro" method="post" action="upload.php" enctype="multipart/form-data">
<div class="col-lg-6">
<div class="form-group">
<label>Product Tags</label>
<textarea class="form-control" rows="2" name="pTags" id="PTags"></textarea>
<p class="help-block">Add Tags to your products to enable faster search.</p>
</div>
<div class="form-group">
<label>Product Expiry Date</label>
<input type="text" name="pExpDate" id="datepicker" class="form-control">
<p class="help-block">Until which date will product be displayed.</p>
</div>
<div class="form-group">
<label>Upload Main Image</label>
<input type="file" name="mainPath" id="mainPath">
<p class="help-block">This image will appear everywhere. Make sure it has a good quality to impress users and size greater than 400px X 400px. </p>
</div>
<div class="form-group">
<label>Upload Sub Image 1</label>
<input type="file" name="sub1" id="sub1">
<p class="help-block">Make sure image has a good quality to impress users and size greater than 400px X 400px. </p>
</div>
<div class="form-group">
<label>Upload Sub Image 2</label>
<input type="file" name="sub2" id="sub2">
<p class="help-block">Make sure image has a good quality to impress users and size greater than 400px X 400px. </p>
</div>
<div class="form-group">
<label>Upload Sub Image 3</label>
<input type="file" name="sub3" id="sub3">
<p class="help-block">Make sure image has a good quality to impress users and size greater than 400px X 400px. </p>
</div>
<input type="submit" value="Upload Image" name="submit" class="btn btn-default">
</div>
</form>
PHP代碼
if(isset($_POST['submit'])){
/*Uploading main image*/
$filetmp = $_FILES["mainPath"]["tmp_name"];//getting error here
$filename = $_FILES["mainPath"]["name"];//getting error here
$filepath = "../uploads/".$filename;
move_uploaded_file($filetmp, $filepath);
/*Uploading sub image1*/
$filetmp1 = $_FILES["sub1"]["tmp_name"];//getting error here
$filename1 = $_FILES["sub1"]["name"];//getting error here
$filepath1 = "../uploads/".$filename1;
move_uploaded_file($filetmp1, $filepath1);
/*Uploading sub image2*/
$filetmp2 = $_FILES["sub2"]["tmp_name"];//getting error here
$filename2 = $_FILES["sub2"]["name"];//getting error here
$filepath2 = "../uploads/".$filename2;
move_uploaded_file($filetmp2, $filepath2);
/*Uploading sub image3*/
$filetmp3 = $_FILES["sub3"]["tmp_name"];//getting error here
$filename3 = $_FILES["sub3"]["name"];//getting error here
$filepath3 = "../uploads/".$filename3;
move_uploaded_file($filetmp3, $filepath3);
}
你得到什麼錯誤? –
你在哪一行發生什麼錯誤? –
請參閱我的PHP代碼。我添加的註釋//得到錯誤這裏 – Student