我在PHP中编写了一个简单的PDF上传器。它工作正常,PDF上传很好。但是我想打印文件名和文件路径(保存位置)。在upload.php表单上。这可能吗?
upload.php的
<form action="../pdf/upload_pdf2.php" method="POST" enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="image"/>
<label><?php echo strlen($filename ) > 0 ? $filename : "" ?> will be saved to /public_html/dev/pdf</label>
<p> </p>
<input type="submit" class="upload-button"/>
</form>
upload_pdf2.php
<?php
if(isset($_FILES['image'])){
$errors= array();
$file_name = $_FILES['image']['name'];
$file_size =$_FILES['image']['size'];
$file_tmp =$_FILES['image']['tmp_name'];
$file_type=$_FILES['image']['type'];
$file_ext=strtolower(end(explode('.',$_FILES['image']['name'])));
$extensions = array("jpeg","jpg","png","pdf");
if(in_array($file_ext,$extensions )=== false){
$errors[]="extension not allowed, please choose a JPEG or PNG file.";
}
if($file_size > 2097152){
$errors[]='File size must be excatly 2 MB';
}
if(empty($errors)==true){
move_uploaded_file($file_tmp,"../pdf/".$file_name);
echo "File uploaded sucessfully";
}else{
print_r($errors);
}
}
?>