首页  编辑  

PHP文件上传脚本,支持curl指令的标准上传

Tags: /PHP/   Date Created:
A PHP script to support CURL command to upload file.
// upload.php
<?php
$uploaddir = '/data/upload/';
foreach($_FILES as $upfile)
{
$uploadfile = $uploaddir.$upfile['name'];
chmod($upfile['tmp_name'], 777);
if(move_uploaded_file($upfile['tmp_name'], $uploadfile))
//iif ($upfile['size'] > 0)
{
chmod($uploadfile, 0666);
echo "true";
}
else
{
echo $_FILES['file']['error'];
echo "false";
}
}
?>
测试页面upload.html,HTML for test
<html>
<head>
<title>Test upload</title>
</head>
<body>
<h2>Select files to upload</h2>
<form name="upload" method="POST" enctype="multipart/form-data"
action="/upload.php">
<input type="file" name="file1"><br>
<input type="file" name="file2"><br>
<input type="file" name="file3"><br>
<input type="file" name="file4"><br>
<input type="file" name="file5"><br>
<input type="file" name="file6"><br>
<input type="submit" name="submit" value="Upload">
<input type="hidden" name="test" value="value">
</form>
</body>
</html>
CURL上传文件测试指令:
curl -F "file=@test_filename.txt" http://server.url.com/upload.php