PHP图像上传问题

I'm using a simple form to upload an image and save it into a folder called "images". Here's the form, which is embedded in php.

echo "
<form method = 'POST' action = 'uploadPic.php'>
<input type = 'hidden' name = 'mvID' value = '$mvID' /> 
<input type = 'file' name = 'pic' />
<input type = 'submit' value = 'Upload' />
</form>
";

Where $mvID is an integer.

Here's the upload code:

move_uploaded_file($_FILES['pic']['tmp_name'], "images/" . $_POST['mvID'] . ".jpg");

I want the file to be saved in the folder "images" as $mvID.jpg. Don't worry about file restrictions, I'll take care of that later.

Unfortunately, this doesn't save any files in the folder. It doesn't do anything, like report any errors.

Any help would be appreciated.

First of all you should add error handling, see for example the manual.

Second, to be able to post a file, you need to add enctype="multipart/form-data" to the form:

<form method='POST' action='uploadPic.php' enctype='multipart/form-data'>

If you do a proper Google Search, the W3 schools tutorial should be on top of the list. It tells you everything you need to know.

For starters, you created the form incorrectly. You need the enctype attribute. (Example of code shown below)

<html> <body>

<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>

</body> </html>

As stated by the tutorial:

The enctype attribute of the tag specifies which content-type to use when submitting the form.