I have a form(HTML, PHP) that lets the end user upload a file to update the database(MySQL) with the records in the uploaded file(specifically .csv). However, in the phpscript, I can only get the filename and not the complete path of the file specificed. fopen() fails due to this reason. Can anyone please let me know how I can work on finding the complete path?
HTML Code:
<html>
<head>
</head>
<body>
<form method="POST" action="upload.php" enctype="multipart/form-data">
<p>File to upload : <input type ="file" name = "UploadFileName"></p><br />
<input type = "submit" name = "Submit" value = "Press THIS to upload">
</form>
</body>
</html>
PHP Script:
<?php
.....
......
$handle = fopen($_FILES["UploadFileName"]["name"], "r"); # fopen(test.csv) [function.fopen]: failed to open stream: No such file or directory
?>
php $path = "C:\\test_folder\\folder2\\folder4"; $sub_folder = scandir($path); $num = count($sub_folder); for ($i = 2; $i < $num; $i++) { if(is_file($path. '\\'.
When the Upload Button is clicked, the filename is extracted from the FileName property using the GetFileName function of the Path class. Then the uploaded File is saved into the Uploads Folder (Directory) using SaveAs method.
$ext; $final_pathdir = $dirname . $image_name3; $suc = move_uploaded_file($_FILES['fileimg1']['tmp_name'], $final_pathdir); if ($suc > 0) { echo "Image uploaded successfully"; } else { echo "Error : " . $_FILES['filimg1']['error']; } ?>
name
refers to the filename on the client-side. To get the filename (including the full path) on the server-side, you need to use tmp_name
:
$handle = fopen($_FILES["UploadFileName"]["tmp_name"], 'r');
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With