Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
255 views
in Technique[技术] by (71.8m points)

php - Posting input type file problem No Value posted

I have a form where I'm posting different fields and every type of field posted seems to work except the input File type.

I'm using var_dump($_POST); and all the other fields are there but nothing in the input type file.

My form part looks like this:

<form enctype="multipart/form-data" id="ajax-form" action="index2.php" method="POST" data-ajax="true">

and works well for everything else.

If there anything that's different in the input type file?

<input type="text" id="myid" name="myid" value="" /> ..This posts value

<input id="theimage" name="theimage" type="file" /> .. does not post value

Any ideas anyone?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Files are stored in $_FILES, not $_POST

http://php.net/manual/en/reserved.variables.files.php $_FILES variable

http://www.php.net/manual/en/features.file-upload.php Manual on PHP File Uploads.

To handle the file (no error checking):

$ROOT = "/path/to/store/files";
foreach($_FILES as $file => $details)
{   // Move each file from its temp directory to $ROOT
    $temp = $details['tmp_name'];
    $target = $details['name'];
    move_uploaded_file($temp, $ROOT.'/'.$target);
}

See also http://www.php.net/manual/en/function.move-uploaded-file.php for more examples.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...