0

Getting an issue with the upload image part from the client.

We have a php form called entry where the client will enter some information that we needs to upload an image. After submitting, the information will be saved into an xml file called data.xml and it will be shown on an html file called display.html

The image have to be saved into a folder called upload. We have this code but I think somewhere we are doing it wrong because it's not working.

This is the part for the image: PHP Code:

    $_FILES['file'];
$_FILES["file"]["name"];
$_FILES["file"]["type"];
$_FILES["file"]["size"];
$_FILES["file"]["tmp_name"];
$_FILES["file"]["error"];

if(isset($_POST["file"]['submit'])) {
if ($_FILES["file"]["error"] > 0) {
    echo "Error: " . $_FILES["file"]["error"] . "<br>";
}
else {
    move_uploaded_file($_FILES["file"]["tmp_name"], "upload/" . $_FILES["file"]["name"]);
    echo "<br>Stored in: " . "upload/" . $_FILES["file"]["name"];
}
} echo $doc->save($file);   } ?>

And in the body html we have this:

<label for="file">Image:</label> <input type="file" name="file" id="file" action:"entry.php" method:"post" entype:"multipart/form-data"><br>

And also it doesn't save anything in the data.xml file. If I remove this code and leave it as it is, the information are saved in the xml form and the display is working.

Can anyone help please?

Thank you

2 Answers 2

1

firstly you need to use form and input type submit.

    <form action="upload_file.php" method="post"
enctype="multipart/form-data">
<label for="file">Filename:</label>
<input type="file" name="file" id="file"><br>
<input type="submit" name="submit" value="Submit">
</form>

also You have a spelling mistake in enctype:"multipart/form-data" you missed c..

Sign up to request clarification or add additional context in comments.

4 Comments

still not working . Do I need to do something extra? write something in the html file?
I correct the spelling mistake..about the submit button we have one <button type="submit" name="submit" id="submit" class="sub" onClick="window.open('display.html')">Submit</button> and when is pressed we want the information to be saved in the xml file but also display it to the html form
I tryed also with the way you gave it to me but still not working i wrote it like this <input type="submit" name="submit" value="Submit" class="sub" onClick="window.open('display.html')"/>
did it.. wrote it as you gave it to me, double check the code but nothing. I am thinking if I have to insert any code into the html file
0

Important parts of the code are missing. Assuming that you've done everything else correctly, and your problem is that it doesn't save anything in the xml file,you should add the below code just after your second echo:

//foreach takes keys and values from all file input types
foreach($_FILES as $item => $val){ 
$val=$_FILES["$item"]["name"];   //save each file's name to $val
$fileNode=$doc->createElement($item, $val); //create a new file element(file is an image in your case)
$entry->appendChild($fileNode); //add the file element as a child of another element - $entry must be initialized from before
} 

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.