我最近一直在尝试PHP,到目前为止一直很好,直到我碰到了一堵砖墙.这是我的一小段代码.它允许我上传一个文件,但我想要的是能够上传多个文件.
这是PHP和HTML文件:
<html>
<head>
<meta charset="utf-8" />
<title>Ajax upload form</title>
<script src="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript" src="https://www.google.com/jsapi"></script>
<script type="text/javascript">
function sendfile(){
var fd = new FormData();
for (var i = 0, len = document.getElementById('myfile').files.length; i < len; i++) {
fd.append("myfile", document.getElementById('myfile').files[i]);
}
$.ajax({
url: 'uploadfile.php',
data: fd,
processData: false,
contentType: false,
type: 'POST',
success: function(data){
alert(data);
}
});
}
</script>
</head>
<body>
<form action="uploadfile.php" method="post" enctype="multipart/form-data" id="form-id">
<p><input id="myfile" type="file" name="myfile" multiple=multiple/>
<input type="button" name="upload" id="upload" value="Upload" onclick="sendfile()" id="upload-button-id" /></p>
</form>
</body> …Run Code Online (Sandbox Code Playgroud) 我有两个 csv 文件,我想从这两个文件的合并中创建第三个 csv。我的文件如下所示:
数量 | 状态
1213 | 已关闭
4223 | 开放
2311 | 打开
另一个文件有这个:
数量 | 代码
1002 | 9822
1213 | 1891
4223 | 0011
因此,这是我试图循环的小代码,但它不会打印添加了与正确值匹配的第三列的输出。
def links():
first = open('closed.csv')
csv_file = csv.reader(first)
second = open('links.csv')
csv_file2 = csv.reader(second)
for row in csv_file:
for secrow in csv_file2:
if row[0] == secrow[0]:
print row[0]+"," +row[1]+","+ secrow[0]
time.sleep(1)
Run Code Online (Sandbox Code Playgroud)
所以我想要的是这样的:
数量 | 状态 | 代码
1213 | 关闭 | 1891
4223 | 打开| 0011
2311 | 打开| 空白不匹配
我想将结果添加到数组并在屏幕上打印.这是我的代码,什么都没有打印...有人可以帮我看看.
include('config.php');
$con = mysql_connect($host, $username, $password);
if (!$con){
die('Could not connect: ' . mysql_error());
}
mysql_select_db('members', $con) or die(mysql_error()) ;
$sql = "SELECT * FROM people where status like '%married%' ";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result)){
$result_array[] = $row['id']; // <-------**here**
}
return $result_array;
echo($result_array);
mysql_close($con);
Run Code Online (Sandbox Code Playgroud) 这段代码有什么问题吗?我想要它打印名称和地址 - 每个都在一个单独的行上,但它们都出现在一行中.
这是代码
<?php
$myname = $_POST['myname'];
$address1 = $_POST['address1'];
$address2 = $_POST['address2'];
$address3 = $_POST['address3'];
$town = $_POST['town'];
$county = $_POST['county'];
$content = '';
$content .="My name = " .$myname ."\r\n";
$content .="Address1 = " .$address1 ."\n";
$content .="Address2 = " .$address2 ."\n";
$content .="Address3 = " .$address3 ."\n";
$content .="town = " .$town ."\n";
$content .="county = " .$county ."\n";
echo $content;
?>
Run Code Online (Sandbox Code Playgroud)
看起来'\n'字符不起作用.
我正在尝试遍历字典并附加到字符串 - 这里是代码:
mylist= {'name':'james', 'age': '23', 'time': 'next'}
myquery = "select * from players where"
for k, v in mylist.items():
myquery += "%s=%s and" % (k, v),
print myquery
Run Code Online (Sandbox Code Playgroud)
这是打印'select * from maintable where age=23 and name=jame and time=next and'
我的问题是在结果的末尾有一个'和'.
如何在没有最后一个的情况下运行for循环?
任何帮助,将不胜感激.
我正在尝试在内容中添加一个php会话,如下所示,但它只是显示一个空页面.我确信逃脱不正确.
echo "<meta http-equiv=\"refresh\" content=\"0;URL=$_SESSION['name'];\">";
Run Code Online (Sandbox Code Playgroud)
这就是我想要实现的目标.
$_SESSION['name'] = 'somepage.php'
Run Code Online (Sandbox Code Playgroud)
我想将会话添加到URL中,以便重定向到'somepage'.
我有这个小代码,它给了我AttributeError:'NoneType'对象没有属性'group'.
import sys
import re
#def extract_names(filename):
f = open('name.html', 'r')
text = f.read()
match = re.search (r'<hgroup><h1>(\w+)</h1>', text)
second = re.search (r'<li class="hover">Employees: <b>(\d+,\d+)</b></li>', text)
outf = open('details.txt', 'a')
outf.write(match)
outf.close()
Run Code Online (Sandbox Code Playgroud)
我的目的是读取一个.HTML文件,查找<h1>标签值和员工数量,并将它们附加到文件中.但由于某些原因,我似乎无法做到正确.非常感谢您的帮助.
我不知道我做错了什么,但这个小的ftp代码不会传输文件.我一直在
文件"example.py",第11行,在?ftp.storlines("STOR"+文件,打开(文件))
ftplib.error_perm:550 /home/helen/docs/example.txt:不允许操作
这是代码:
import ftplib
file = '/home/helen/docs/example.txt'
ftp = ftplib.FTP('domain', 'user', 'password')
print "File List: "
files = ftp.dir()
ftp.cwd("/upload/")
ftp.storlines("STOR " + file, open(file))
f.close()
s.quit()
Run Code Online (Sandbox Code Playgroud)
任何帮助,将不胜感激.
我有这段代码,虽然它有效 - 在我的data.frame中处理(7分钟)530,000条记录需要相当长的时间.
我的目标是在我的框架中创建一个字段,并根据people $ Month的值填充它,如下所示:
for (i in 1:nrow(people)) {
if(people$Month[i]=='JAN') {
people[i, 'new_month'] <- "1"
}
else if(people$Month[i]=='FEB') {
people[i, 'new_month'] <- "2"
}
else if(people$Month[i]=='MAR') {
people[i, 'new_month'] <- "3"
}
else if(people$Month[i]=='APR') {
people[i, 'new_month'] <- "4"
}
else if(people$Month[i]=='MAY') {
people[i, 'new_month'] <- "5"
}
else if(people$Month[i]=='JUN') {
people[i, 'new_month'] <- "6"
}
else if(people$Month[i]=='JUL') {
people[i, 'new_month'] <- "7"
}
else if(people$Month[i]=='AUG') {
people[i, 'new_month'] <- "8"
}
else if(people$Month[i]=='SEP') {
people[i, 'new_month'] <- …Run Code Online (Sandbox Code Playgroud) 只是在寻找一种更有效的方法来在列表中添加一个非常大的数字。我知道我可以使用 sum() 函数,但我想知道是否还有其他更好或更有效的方法。
nums = list(range(17832931))
ans = sum(nums)
Run Code Online (Sandbox Code Playgroud)
谢谢你的建议