Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
244 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 Reply

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...