Jump to content

Uploading Files


dtayler

Recommended Posts

I am having a problem with accessing the $_FILES array. I find that it sometimes has data in, and sometimes is empty! (I have to submit the first file, go back, submit again....several times, and then will get data) I am running Apache locally, and have checked the php settings for max file size, upload allowed, global variables etc., as recommended in the articles I've found on this. My code is in two php files as given below. PLEASE can somebody help.

upload.php
html>
<head></head>
<body>

<form enctype="multipart/form-data" method="post" action="upload2.php" >
<input type="file" name="newname">
<input type="submit">
</form>

</body>
</html>

upload2.php
html>
<head></head>
<body>



<?php

echo '<br> Files contains: name :'.$_FILES['newname']['name'].' temp :'.$_FILES['newname']['tmp_name'].' type :'.$_FILES['newname']['type'].' size :'.$_FILES['newname']['size'].' error :'.$_FILES['newname']['error'].'<br>';

?>
</body>
</html>
Link to comment
https://forums.phpfreaks.com/topic/6803-uploading-files/
Share on other sites

Change you test to be the following and see if you have the same problem:
[code]
<?php
if (isset($_POST['submit'])) echo '<pre>' . print_r($_FILES,true) . '</pre>';
?>
<html>
<head></head>
<body>

<form enctype="multipart/form-data" method="post" action="<? echo $_SERVER['PHP_SELF'] ?>" >
<input type="file" name="newname"><br>
<input type="submit" name="submit" value="Upload File">
</form>

</body>
</html>[/code]
With this code you don't have to hit the "back" button to get back to the form and the dump the $_FILES array is nicely formatted.

Ken
Link to comment
https://forums.phpfreaks.com/topic/6803-uploading-files/#findComment-24739
Share on other sites

[!--quoteo(post=362510:date=Apr 7 2006, 08:36 AM:name=kenrbnsn)--][div class=\'quotetop\']QUOTE(kenrbnsn @ Apr 7 2006, 08:36 AM) [snapback]362510[/snapback][/div][div class=\'quotemain\'][!--quotec--]
Change you test to be the following and see if you have the same problem:
[code]
<?php
if (isset($_POST['submit'])) echo '<pre>' . print_r($_FILES,true) . '</pre>';
?>
<html>
<head></head>
<body>

<form enctype="multipart/form-data" method="post" action="<? echo $_SERVER['PHP_SELF'] ?>" >
<input type="file" name="newname"><br>
<input type="submit" name="submit" value="Upload File">
</form>

</body>
</html>[/code]
With this code you don't have to hit the "back" button to get back to the form and the dump the $_FILES array is nicely formatted.

Ken
[/quote]


Thanks Ken, it's easier than going back a page all the time - but I still get the same problem!
Deb
Link to comment
https://forums.phpfreaks.com/topic/6803-uploading-files/#findComment-24752
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.