Where is my uploaded file?
First issue, where is it suppose to be?
Accordint to php.net
Files will, by default be stored in the server's default temporary directory, unless another location has been given with the upload_tmp_dir directive in php.ini. The server's default directory can be changed by setting the environment variable TMPDIR in the environment in which PHP runs
So I go to my php.ini file and find
upload_tmp_dir = "\xampplite\tmp"
And let me go ahead and post by xhtml code:
<div class="t2_c2">
<form name="f9" enctype="multipart/form-data" action="pi5.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input name="ufile" type="file" class="te7" />
</form>
</div>
This is a form inside a column, inside a table.
And last but not least the javascript that submits this form.
document.f9.submit();
Because there i开发者_高级运维s alot of files non of which appear to be my file in the temp directory I add some debug php code to look at the $_FILES super global associative array.
The code
print_r($_FILES['ufile']);
returns this info.
Array ( [name] => c0.css [type] => text/css [tmp_name] => F:\xampplite\tmp\php317C.tmp [error] => 0 [size] => 10652 ) The file c0.css
on a second run in produces
Array ( [name] => here.gif [type] => image/gif [tmp_name] => C:\Users\a\AppData\Local\Temp\phpC256.tmp [error] => 0 [size] => 8549 )
which I find odd, that this is not specified in the php.ini file and proves php.net documentation invalid.
Life is lookin good until I go to the [tmp_name] and find this:
No file.
My plan was to change my php.ini file so that the file is downloaded directly to where I want it, but according the answers below, the file only lasts as long as the php script is running, so this does not appear to be an option or at minimal a simple option. That was why I did not use the move function at first.
The tmp_name
is only valid for the lifetime of the PHP script execution, after which the file is cleaned up. You need to move_uploaded_file()
to a permanent location in the same script execution for it to persist.
You need to move the uploaded file as it could have been stored temporarily. http://ca.php.net/manual/en/function.move-uploaded-file.php
精彩评论