העלת קבצים.

Crow4U

New member
העלת קבצים.

עשיתי את הקוד הבאה בשביל להעלות קבצים לשרת.. אך העלה אינה מתבצעת.. הנה הקוד:
<? if(!$_GET['Action']) { header("Location: Upload.php?Action=Main"); } ?> <Html dir=rtl> <Head> <Style> TABLE { FONT-SIZE: 9pt; FONT-FAMILY: Arial; BORDER-COLLAPSE: collapse } </Style> </Head> <Body bgcolor="#FFFFFF" text="#000000"> <BaseFont Face=Arial> <? if($_GET['Action'] == "Main") { ?> <form action="Upload.php?Action=Upload" method="Post" enctype="multipart/form-data"> <p align=center> <font size=5 color=red face=arial>מערכת העלת קבצים</font><br><Br> <table border="0" cellpadding="0" cellspacing="0" width="100%"> <tr> <th><input type="file" size="20" name="file1"></th> </tr> <tr><td height=10></td></tr> <tr> <th><input type="file" size="20" name="file2"></th> </tr> <tr><td height=10></td></tr> <tr> <th><input type="file" size="20" name="file3"></th> </tr> <tr><td height=10></td></tr> <tr> <th><input type="file" size="20" name="file4"></th> </tr> <tr><td height=10></td></tr> <tr> <th><input type="file" size="20" name="file5"></th> </tr> <tr><td height=10></td></tr> <tr> <th><input type="file" size="20" name="file6"></th> </tr> <tr><td height=10></td></tr> <tr> <th><input type="file" size="20" name="file7"></th> </tr> <tr><td height=10></td></tr> <tr> <th><input type="file" size="20" name="file8"></th> </tr> <tr><td height=10></td></tr> <tr> <th><input type="file" size="20" name="file9"></th> </tr> <tr><td height=10></td></tr> <tr> <th><input type="file" size="20" name="file10"></th> </tr> <tr><td height=10></td></tr> <tr> <td align=center><INPUT TYPE="submit" value="שלח"></td> </tr> </table> </p> </FORM> <? } if($_GET['Action'] == "Upload") { for ($i=1 ; $i<=10 ; $i++) if(!empty($_POST['file".$i."'])) { move_uploaded_file ($_POST['file".$i."'],"/"); echo "The ".$_POST['file".$i."']." Uploaded.<br>"; } } ?> </BaseFont> </Body> </Html>​
מה עלי לעשות כדי שהעלת הקבצים תעבוד?
 

GPhoenixX

New member
אני לא מכיר את הפונקציה הזאת ..

אני מתמש בCopy אבל בכל מקרה, תוודא שיש לך הרשאה להעלות קצבצים לתיקיה אליה אתה מעלה,תעשה chmod 777.
 

Crow4U

New member
שינית את הקוד שלי לקוד הבא:

for ($i=1 ; $i<=10 ; $i++) $thefile = $_FILES['file".$i."']; if(!empty($thefile)) { move_uploaded_file ($thefile,"/"); echo "הקובץ ".$thefile." עלה בהצלחה!<br>"; } else { echo "שגיאה"; }​
וזה רושם לי שגיאה ולא מעלה את הקבצים..
 

N i X

New member
לא נכון מבחינה לוגית מה שאתה עושה..

ראה דוגמא: (נחש מאיפה...)
Handling file uploads add a note user at php dot net 26-Jul-2003 08:16 To add an example to the bart at combodata dot nl's note: When you're using this type of form: <form name="" method="post" action="dostuff.php" enctype="multipart/form-data" > <input type="file" name="dat[foto]" /> <input type="file" name="dat[banner]" /> <input type="file" name="dat[pdf]" /> </form> You can refer to the uploaded files this way: $_FILES["dat"]["tmp_name"]["foto"] name: $_FILES["dat"]["name"]["foto"] size: $_FILES["dat"]["tmp_name"]["foto"]​
 

Crow4U

New member
לא כל כך הבנתי :\

אתה יכול להגיד לי איך אני מכניס את מה שאמרת לי לקוד שלי? פשוט לא הבנתי אותך :(
 

N i X

New member
תראה...

אני יגיב לך בפרוט מחר, כי פשוט עכשיו חזרתי הביתה ו... תראה את השעה של ההודעה ;) בקצרה: אתה אמור לקבל מערך תלת מימדי של $_FILES. קודם כל, הטופס אמור להיות משהו כזה:
<form name="" method="post" action="bla4.php" enctype="multipart/form-data" > <input type="file" name="myfile[]" /> <input type="file" name="myfile[]" /> <input type="file" name="myfile[]" /> </form>​
עכשיו, יש לנו מערך של קבצים, שלכל אחד מהם אתה פונה כך:
echo $_FILES["myile"]["name"][0]; // first file echo $_FILES["myile"]["name"][1]; // 2nd file​
קח את כל מה שרשמתי בע"מ, כי לי ניסתי שום דבר מהנ"ל, ולכן איני יכול להבטיח שזה באמת פועל, ניסיתי להסביר את הרעיון, ולא לכתוב את הקוד.
 

erezhod

New member
ניסיתי לבנות קוד יותר פשוט

אבל זה גם לא עובד
חחח אני מנחש שמשהו לא בסדר עם הפונקציה עצמה שהיא move_uploaded_dir. יכול להיות שלא כתבתי את זה נכון?
<?php if(!isset($_GET['a'])) { print ""; } elseif($_GET['a'] == "send") { $uploaddir = '/home/erez/public_html/uploads/'; move_uploaded_file($_FILES['myfile']['name'],$uploaddir); print $_FILES['myfile']['name']."<br>הועלה בהצלחה"; exit; } ?> <form name="" method="post" action="upload.php?a=send" enctype="multipart/form-data"> <input type="hidden" name="MAX_FILE_SIZE" value="20000"> Send this file: <input name="myfile" type="file"> <input type="submit" value="Send File"> </form>​
 

erezhod

New member
סליחה תיקון טעות

אמרתי move_uploaded_dir זה move_uploaded_file Sorry.
 

Crow4U

New member
עוד שאלה!

ב Asp יש דבר שנקרא Session.ID שזה אידי שנוצר אוטומטי לכל משתמש שנכנס לשרת והוא יחודי לכל משתמש.. האם יש דבר כזה גם ב Php? תודה.
 

shanor

New member
מממ...

כן, בטח שיש, אם קבעת למשתמש שלך SESSION, הוא יקבל SESSION ייחודי רק לו. אין מצב שיתקיימו שני סשנים זהים באותו רגע. בקשר ל-ID של כך אחד ואחד.... נו באמת, חפש כאן: www.php.net/session מבטיח לך שעם קצת סבלנות ולא הרבה מאמץ, תמצא את התשובה אי שם בפרק שנקרא SESSION HANDLING, בכתובת שציינתי. שנאור.
 
למעלה