Html/php code not behaving as expected
Author: Dave R.I am developing using xampp with mysql and php before uploading to the world
I have a simple files upload file routine which works in a standalone .php file
When I embed this code into a website X5 php page using the HTML code object it fails with 'Warning: Undefined array key "ufile" '
Here is the code simplified for ease of inspection.
here's the form for gathering the files
<html>
<div class="form-popup" id="picsForm" style = "width:20em;">
<label style = "width:20em;">If you have pictures, upload them here.</label>
<br>
<form method="post" action="" enctype="multipart/form-data">
<input name="ufile[]" id="file" type="file" multiple="multiple" >
<input type='submit' name='pics' style=" margin-top:8px; float:right; height:2em; background-color: #7B9BF5;" value='Upload pictures'>
</form>
</div>
now the php for collection and storing the uploaded files
<?php
if(isset($_POST['pics']))
{
$total_count = count($_FILES['ufile']['name']);
for( $i=0 ; $i < $total_count ; $i++ )
{
$tmpFilePath = $_FILES['ufile']['tmp_name'][$i];
$newFilePath = $_SERVER['DOCUMENT_ROOT'] ."/pics/" . $_FILES['ufile']['name'][$i];
if(move_uploaded_file($tmpFilePath, $newFilePath))
{
// do stuff
}
else
{
//error routines
}
}
}
Any help would be appreciated thank you
Hi Dave
?> Maybe?
Author
Sorry I missed that off the post. It's there in the code!
PS If I turn warnings off there are no messages, but it still doesn't work.
... the code is valid ...
... maybe you wrong the path of the save folder ...
ciao
.
Author
No, the path is correct as you can see I am using $SERVER['DOCUMENT_ROOT'].
If I create a .php file with just this code, and run it from any browser, it works fine. See attachment.
I have a feeling that there is something I cannot see in the X5 wrapping around my html object.
I'm not blaming Incomedia!! I just cannot spot what it is.
Thanks
... path OK; ... ...you assigned the extension *.php to the page ...?...
... eventually post the LINK of that page to be able to verify...
.
Author
Yes .php extension
I cannot post a link because it's running on my local xampp server with php7.1
However here is the file as exported by Website X5 and the appropriate css file
Thanks
... wait for other experts; ... unfortunately I don't have a PC, and I can't download or even try ...
... however I confirm that your PHP + HTML code is valid...
ciao
.
Author
Thanks for trying
Hello,
For me it works fine.
And the pics directory after upload is:
Put the code into HTML object and change page property to php like here
And publish your project to the webserver. Cannot works into preview mode
Hope this helps
Enjoy!
Axel
Author
Bonsoir
J'ai déjà fait exactement ce que vous proposez.
Ça me rend fou!!
Did you use the code from my original post, or the code in the attachment test.zip?
The test.zip contains the code with incomedia X5 wrapping
The code shown in my original post works fine with exactly the same setup you have.
The code in test.zip is the problem.
Merci et bonne soirée.
Dave
Hello Dave,
J'ai pris le code qui se trouve dans le premier message et j'ai fait ce que je viens de poster ci avant.
Rien de plus.
Je suggère d'essayer dans une page sans autre objet (ce que j'ai fait). Il y a peut être un conflit dans la page actuelle !
Le code généré dans ma page est ici:
</div>
<div id="imCell_1" class="" > <div id="imCellStyleGraphics_1"></div><div id="imCellStyleBorders_1"></div><div id="imHTMLObject_197_01" class="imHTMLObject" style="text-align: center; height: 350px; width: 100%; overflow: auto;"><html>
<div class="form-popup" id="picsForm" style = "width:20em;">
<label style = "width:20em;">If you have pictures, upload them here.</label>
<br>
<form method="post" action="" enctype="multipart/form-data">
<input name="ufile[]" id="file" type="file" multiple="multiple" >
<input type='submit' name='pics' style=" margin-top:8px; float:right; height:2em; background-color: #7B9BF5;" value='Upload pictures'>
</form>
</div>
</html>
<?php
if(isset($_POST['pics']))
{
$total_count = count($_FILES['ufile']['name']);
for( $i=0 ; $i < $total_count ; $i++ )
{
$tmpFilePath = $_FILES['ufile']['tmp_name'][$i];
/* Here the directory is up the server directory */
$newFilePath = $_SERVER['DOCUMENT_ROOT'] ."/pics/" . $_FILES['ufile']['name'][$i];
if(move_uploaded_file($tmpFilePath, $newFilePath))
{
// do stuff
echo "Upload done with success !";
}
else
{
//error routines
echo "No file to upload !";
}
}
Le tien n'est pas positionné de la même façon ! Est-ce cela ?
Enjoy!
Axel
J'ai copié du fichier zip, test.php et test.css dans le répertoire de mon serveur
C'est mal présenté mais voila ce qui s'affiche en bas de page.
et le upload fonctionne dans le répertoire /pics qui est au niveau supérieur à mon serveur web.
Author
It's the pancake menu for the site I am trying to load this code.
It's for a members' area and will be unavailable to the general public.
Youcan see the existing site here http://swiftsinthecommunity-cumbria.org.uk/
je pense que c'est l'heure de l'apéritif!
Merci et bonne soirée.