2022年6月10日 星期五

php upload pdf sample

 <?php 

move_uploaded_file($_FILES['fileupname']['tmp_name'],'upload/' . $_FILES['fileupname']['name']);


$files = scandir('upload');

for ($i=2;$i<count($files);$i++){

echo '同學作品:' . $i-1 . '<br>';

echo "<iframe src='upload/$files[$i]'></iframe>" . '<br>';

}

?>


key:

move_uploaded_file

$_FILES[]

tmp_name

upload/

scandir

count($files)

<iframe src='upload/$files[$i]'>

pdf upload sample

 <?php 

move_uploaded_file($_FILES['fname']['tmp_name'],'upload/' . $_FILES['fname']['name']);

$files = scandir('upload');

for($i=2;$i<count($files);$i++)

{

echo '同學上傳作品:' . $i-1 .'<br>';

echo "<iframe src='upload/$files[$i]' width=50% height=50%></iframe><br>";

}

?>

2022年6月9日 星期四

多項式相加

 # -*- coding: utf-8 -*-



# p = 2*x^5 + 3*x^2 + 2*x^1 + 5

# q = 2*x^3 + 3*x^1 + 6

# p+q = ?

# p*q = ?


# ans: 2*x^5 + 2*x^3 + 3*x^2 + 5*x^1+ 11


p = '2*x^5 + 3*x^2 + 2*x^1 + 5'

q = '2*x^3 + 3*x^1 + 6'


print('p=' + p)

print('q=' + q)


pl = p.replace(' ','').split('+')

ql = q.replace(' ','').split('+')

r = {}

for p in pl:

    p =[int(i) for i in p.split('*x^')]

    if len(p)>1:

        if p[1] in r:

            r[p[1]] += int(p[0])

        else:

            r[p[1]] = int(p[0])

    else:

        if 0 in r:

            r[0]+=p[0]

        else:

            r[0]=p[0]


for q in ql:

    q =[int(i) for i in q.split('*x^')]

    if len(q)>1:

        if q[1] in r:

            r[q[1]] += int(q[0])

        else:

            r[q[1]] = int(q[0])

    else:

        if 0 in r:

            r[0]+=q[0]

        else:

            r[0]=q[0] 


d =[ [k,v] for k,v in r.items()]

d.sort()

d.reverse()

sss = []

for i in d:

    sss.append(str(i[1]) + '*x^' + str(i[0]))

sss = '+'.join(sss)

print('p+q = ' + sss[:-4])



# multiply p q

if len(pl[-1])==1:

    pl[-1]=pl[-1]+'*x^0'

if len(ql[-1])==1:

    ql[-1]=ql[-1]+'*x^0'




pl = [i.split('*x^') for i in pl]

ql = [i.split('*x^') for i in ql]


pl = [[int(j) for j in i] for i in pl]

ql = [[int(j) for j in i] for i in ql]


# print(pl)

# print(ql)


r1 = []

lp = len(pl)

lq = len(ql)

for i in range(lp):

    for j in range(lq):

        r1.append([pl[i][0]*ql[j][0],pl[i][1]+ql[j][1]])

# print(r1)


r = {}

for i in r1:

    if i[1] in r:

        r[i[1]]+=i[0]

    else:

        r[i[1]]=i[0]

# print(r)


d =[ [k,v] for k,v in r.items()]

d.sort()

d.reverse()

sss = []

for i in d:

    sss.append(str(i[1]) + '*x^' + str(i[0]))

sss = '+'.join(sss)

print('p*q = ' + sss[:-4])

2022年6月5日 星期日

php html upload file sample

file upload 分享


建upload子目錄


fup.html 步驟


dw中插入

1. 表單

2. file 欄位, name設為 upfilename

3. submit 按鈕



fup.html 內容


<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />


<form method="post" action="fup.php" enctype="multipart/form-data" >


<input name="my_file" type="file">

<input name="submit" type="submit" value="上傳">


</form>




fup.php  內容

move_uploaded_file($_FILES['upfilename'][tmp_name],'upload/' . $FILES['upfilename']['name']);

 

Perfect Number

 #完美數


# n = 28

for n in range(1,1001):

    a = []

    for i in range(1,n):

        if n%i==0:

            a.append(i)

    if sum(a)==n:

        print(n,':perfect number')


runfile('C:/Users/j945935/.spyder-py3/untitled1.py', wdir='C:/Users/j945935/.spyder-py3')

6 :perfect number

28 :perfect number

496 :perfect number

XAXB

 # XAXB

p = '1234'

for q in [ '1234','1235','4321','4231','5678']:

    ac = 0

    bc=0

    for i in range(4):

        if p[i]==q[i]:

            ac+=1

        elif p[i] in q:

            bc+=1

    print(f'{ac}A{bc}B')


runfile('C:/Users/j945935/.spyder-py3/untitled0.py', wdir='C:/Users/j945935/.spyder-py3')

4A0B

3A0B

0A4B

2A2B

0A0B






2022年6月2日 星期四

php mysql

 <?php 

$conn2 = mysqli_connect('localhost','root','','test1');

$sqlstr = "select * from user where username = '" . $_POST['username'] . "'";

$result = mysqli_query($conn2,$sqlstr);

echo '<table width="400" border="1">';

while ($row = mysqli_fetch_assoc($result))

{

echo '<tr>';

echo '<td>';

echo $row['username'];

echo '</td>';

echo '<td>';

echo $row['password'];

echo '</td>';

echo '</tr>';

}

echo '</table>';

?>



$sqlstr = "select * from user where username = '" . $_POST['username'] . "'";

1  "select * from user where username = '      "

2   . $_POST['username'] . 

3     " ' "


說明:  

"select ......                 ' "  + $_POST['username']

+ " ' "


實際送出指令為

select * from user where username = ' $_POST['username']'

把字串拆成三段

1   select * from user where username = ' 

2   $_POST['username']

3   ’

最後 1、3 用雙引號包起來,再用句點把字串連起來。