Selecting file names from a folder in php - php

I want to get folder name from my computer in PHP code. I got the following piece of information, on searching on stackoverflow:
<input type="file" name="folder" webkitdirectory directory multiple/>
Directory Chooser in HTML page
But, the issue is the folder gives only one file name in post array.
<?php
echo "I am in page.";
if ( empty($_POST['folder']))
{
?>
<form method="POST">
<div class="container compare_body">
<div class="row">
<div class="col-md-3">
Select a Folder:
</div>
<div class="col-md-3">
<input type="file" name="folder" webkitdirectory directory multiple/>
</div>
<div class="col-md-3">
<button type="submit" class="btn btn-info">List your files</button>
</div>
</div>
</div>
</form>
<?php
}
else
{
print_r($_POST['folder']);
echo "I am in else.";
}
?>
I am in page.WWW.YIFY-TORRENTS.COM.jpgI am in else.
Edit : I tried GET method, which results in the following query:
http://localhost/thrillermovie/yourmovies?folder=2.png&folder=facebook_post.png&folder=callhistorycontrol.png&folder=khan.jpg&folder=minimization.png&folder=obama_knows.png&folder=facebook.png&folder=wildkrafts.png&folder=dekho.png&folder=sub.png&folder=2_batman.png&folder=best+response.png&folder=moore.png&folder=admob.png&folder=adrspeechcode.png&folder=batman_story.png&folder=comparemovies.png&folder=landevicefound.png&folder=it&folder=device-2015-08-19-005229.png&folder=bhakta.png&folder=Screenshot+from+2015-09-19+23%3A16%3A09.png&folder=arrow.png&folder=raghib_comment.png&folder=web_hi_res_512.png&folder=nfa_dfa.png&folder=raghiblul.png&folder=tux.png&folder=lexical.png&folder=likes.png&folder=raghib_lul.png&folder=bluegape.png&folder=con.png&folder=dfa_conversion.png&folder=bhakto+ko.png&folder=mynumber.png&folder=katjuJiReply.png&folder=tifY9AWf_400x400.jpg&folder=kalam.jpg&folder=bk.png&folder=1.png&folder=1_batman.png&folder=mealay.png
but output is only the last folder name.
Please help me to solve the problem.

try the form name name="folder[]" and then process in foreach folder

Related

PHP 8.1 $_FILES missing type property

I am upgrading my website from PHP 7.4 to 8.1 which is causing an unusual issue with $_FILES. I'm trying to upload a new file but nothing happens. This issue cannot be regarding the file size as I'm trying to upload .txt files containing a single word.
Example of my code:
<form action="client.php" method="POST" enctype="multipart/form-data" onSubmit="javascript: return validateFile(this);">
<div class="card-header">
Upload Section
</div>
<div class="card-body">
<div class="position-relative form-group">
<label >Select file from local disk</label>
<input type="file" name="test" size="90" maxlength="500" class="form-control-file">
</div>
<input class="mt-1 btn btn-primary" name='Submit' type='submit' value='Upload File'>
</div>
</form>
When the from is posted the data within $_FILES is like so
test={ name="test.txt, full_path=test.txt, type="", tmp_name="", error={int} 6, size={int} 0}
The PHP website did not have access to the "C:\WINDOWS\Temp" directory. Which was easily fixed by changing the security permissions.

Froala PHP SDK error: Fieldname is not correct. It must be: file

I'm developing an article-publishing utility and I'm using Froala's WYSIWYG textarea text editor that I included in a form, after storing the article's basic infos in the database, I want to store the uploaded images in the text editor on the server , the problem is when I use their php SDK to store images like mentioned in the documentation, I get this error: Fieldname is not correct. It must be: file
this is the html for the form:
<form method="post" class="mt-5" action="<?php echo htmlspecialchars($_SERVER['PHP_SELF']);?>">
<div class="form-group row justify-content-center">
<div class="col-sm-9">
<label for="uname" style="color:#B1DDF1;"><b>Your Article's title</b></label>
<input type="text" id="focusedInput" class="form-control" name="title" placeholder="Make it creative!...">
</div>
</div>
<div class="form-group mt-2">
<label for="comment" style="color:#B1DDF1;"><b>Content goes here...</b></label>
<div id="editor"><textarea class="form-control" cols="200" rows="200"id='edit' name="file" placeholder="Type some text"><h1>This is a heading</h1>
<p>start writing your article here!</p></textarea></div>
</div>
<div class=" row mt-2 justify-content-center">
<input type="submit" class=" col-xs-6" value="Publish me!">
</div>
</form>
and here is a part of the PHP code:
$lastid=$conn->lastInsertId(); // get the new article's id for ressources management
$newarticfold="../LIGHT/articles_ressources/".$lastid;
try{
if(mkdir($newarticfold)){
require("wysiwygphp/lib/FroalaEditor.php");
$path="/Freelancing/CarthageP/test/LIGHT/articles_ressources/".$lastid."/"; //specifying the path from $_SERVER["DOCUMENT_ROOT"]
$resp=FroalaEditor_Image::upload($path);
echo("<div class='alert alert-success'>yaaay images got uploaded yaaaaay</div>");
}
}
I tried changing the name of the textarea to file, read the documentation many times and I tried to google the error message but I didn't find anything regarding it, what can be a possible cause for such a problem and how could it be fixed? Thank you very much in advance!

PHP not sending any data with POST

I have this simple code:
<div class="container">
<div class="row">
<div class="col-md-12">
<div class="titleDiv">
<h1>Image canvas</h1>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="previewDiv">
<img src="#" id="imgPreview">
</div>
<div class="buttonsDiv">
<button type="button" class="rotateButtons" id="rotateLeft">
<i class="fa fa-arrow-circle-left" aria-hidden="true"></i> Rotate left
</button>
</div>
</div>
</div>
<div class="row">
<div class="col-md-12">
<div class="uploadDiv">
<form action="upload.php" method="POST" id="#uploadForm">
<!--<input type="file" name="img" accept="image/*" id="imgUpload">-->
<input type="number" name="number" value="0">
<input type="submit" value="Submit">
</form>
</div>
</div>
</div>
</div>
And on the upload.php file I have only 2 lines of code:
var_dump($_POST);
var_dump($_GET);
When I try to send this data over POST I get an output array(0) { } .
Though when I change the form method to method="GET" everything works normal and I receive the the data great on the upload.php.
I looked the php.ini file (I am using xampp as a local server) and the line ;enable_post_data_reading=Off is commented. Can someone help sort out this problem?
Check if you're actually using your webserver. What's the address on your navigation bar? It should be localhost without some strange ports. If it's pointing to 63342 that could be your problem.
edit: that could happen if you're using an IDE

Cannot upload file through HTML form

I am planning to make a form which has a form through which users can upload a file on the website.
I used a CSS template where a class called pop-up-wrapper and pop up is defined. However, when I use the following code :
<div>
<div class="form-pop-up">
<div class="form-pop-up-wrapper">
<ul class="contact-form">
<form id="form-submit" method="post" enctype="multipart/form-data">
<li>
<p class="iam-white center-al">Upload file</p>
<input type="file" name="resume" id="user-resume">
</li>
<li>
<p> </p>
<input type="submit" name="submit" value="Submit" id="form-submit" class="mar">
</li>
</form>
</ul>
</div>
</div>
</div>
I have a PHP code which validates if any file has been entered by checking with
isset($_FILES['file']
but this always returns 0.
Is there anything in the CSS stylesheet which can lead to this situation where $_FILES is unable to catch the uploaded file?
TIA
You have to use the name in $_FILES, not the type.
isset($_FILES['resume'])
Just a shot here, but I don't think it's your CSS that's causing the problem. Try:
isset($_FILES['resume'])
instead.

Twitter Bootstrap FileUpload issue

I would like to use Twitter Boostrap FileUpload because I like the preview function it offers. This and some text I would like to post to a php script that does the uploading and adds info to a db. I dont necessarily need php to do the uploading of the file if javascript can do it I just need the link too it.
This question has been asked before but I can't find any working answer there. And no I dont want to use bootstrap file-upload that is suggested in the first answer.
In my php code I try to get the imgData with _FILE but its empty. How can I get this?
this is my form:
<form action="php/service.php" method="post">
<div class="control-group">
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="fileupload-preview thumbnail" style="width: 200px; height: 150px;"></div>
<div>
<span class="btn btn-file">
<span class="fileupload-new">Select image</span>
<span class="fileupload-exists">Change</span>
<input type="file" name="imgData" id="imgData" />
</span>
Remove
</div>
</div>
</div>
<div class="control-group">
<textarea rows="3" id="text" class="" name="text" placeholder="Text..."></textarea>
</div>
<div class="control-group">
<button type="submit" id="upload" class="btn" onclick="$('.fileupload').fileupload();">Upload</button>
</div>
</form>
in service.php:
if ($_FILES["imgData"]["error"] > 0) {
echo "Error: " . $_FILES["imgData"]["error"] . "<br />";
} else {
$fileExt = $_FILES["imgData"]["type"];
}
You need to set the encoding type for the form.
<form action="php/service.php" method="post" enctype="multipart/form-data">
I also had difficulties with this bootstrap way of uploading files in IE. There might be some security issues in that one that prevents uploading.

Categories