开发者

php upload file function

开发者 https://www.devze.com 2022-12-26 20:30 出处:网络
I am trying to write a script which uploads a file via a html form. When I click submit nothing happens.

I am trying to write a script which uploads a file via a html form. When I click submit nothing happens.

file: upload_form.html

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>

<form action="do_upload.php" method="post" enctype="multipart/form-data"></form>
<p><strong>File to upload</strong></p>
<p><input name="img1" type="file" size="30" /></p>
<p><input name="submit" type="submit" value="Upolad File" /></p>

</body>
</html>

file: do_upload.php

<?php
if ($_FILES[img1] != "" {
    @copy($_FILES[img1] [tm_name], "/tmp" .$_FILES[img1][name])
    or die("couldnt copy the file");
} else {
    die("no file specified");
}
?>

<HTML>
<head>
<title>Successfull File Upload</title开发者_Python百科>
</head>
<body>

<h1>Success</h1>
<p>You sent: <? echo $_FILES[img1][name]; ?>, a <? echo $_FILES[img1][size]; ?>byte filw with a mime type of <? echo $_FILES[img1][type]; ?></p>

</body>
</HTML>


<form action="do_upload.php" method="post" enctype="multipart/form-data"></form>
<p><strong>File to upload</strong></p>
<p><input name="img1" type="file" size="30" /></p>
<p><input name="submit" type="submit" value="Upolad File" /></p>

to

<form action="do_upload.php" method="post" enctype="multipart/form-data">
<p><strong>File to upload</strong></p>
<p><input name="img1" type="file" size="30" /></p>
<p><input name="submit" type="submit" value="Upolad File" /></p>
</form>

and

if ($_FILES[img1] != "" {

to

if (isset($_FILES['img1'])) {


If you're not receiving any errors at all, add the following lines to the top of your script to ensure that error reporting is set up properly:

error_reporting(E_ALL);
ini_set('display_errors', 'On');
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号