Ziqreey
Ziqreey

Reputation: 33

How To Open Target File Or Folder In PHP

How to open a specific folder in file explorer using PHP, I already tried some code but it just directing to random folder. Please help me.

I have try some code

if(empty($_POST['importdata'])) {
//Bahagian Kekotak Papar Button Import -mula-

echo '<form action = "" method="POST" name="upload_excel" enctype 
="multipart/form-data">';
echo '<fieldset>
<legend>Jadual Import Data Pelajar</legend>
<label>Pilih Fail (CSV) </label>
<input type ="file" name="file" id="file">
<input id="buttonon" type = "submit" name="importdata" value="UPLOAD & 
IMPORT"></fieldset>';

echo '</form>';
}else{
$filename=$_FILES["file"]["tmp_name"];
if($_FILES["file"]["size"]>0) { //jika ada fail CSV
    //jika fail CSV telah dipilih
    $file = fopen($filename,"r");
    while (($getData = fgetcsv($file, 1000, ",")) !== FALSE)
    {
}

Upvotes: 0

Views: 239

Answers (1)

symcbean
symcbean

Reputation: 48357

(this should be a comment, but its too long)

Reading the manual is always a good place to start.

Allowing user direct access to write files on your webserver is inherently very dangerous. The way PHP implements file uploads mitigates many of the risks.

How to open a specific folder in file explorer using PHP

The sentence makes no sense.

Files exist in folders, not the other way around. Do you really want PHP to open up (Micorosf) File explorer showing the directory containing a nominated file? Do you mean to create a copy by "uploading" it from your client? Your code example does not use nominated files / does not attempt to invoke other programs on the host.

it just directing to random folder

No. File uploads always go to the location nominated in your PHP.ini. If no directory is nominated, PHP puts the files in your system temp directory (as determined from your environment variables). And you can determine that location from dirname($_FILES["file"]["tmp_name"])

Upvotes: 1

Related Questions