פורסם 2008 בספטמבר 1317 שנים שלום יש לי אתר לעלאת תמונות שלא מזמן פתחתי יש עכשיו כמה בעיותNotice: Undefined index: userfile in /www/host2.nu/u/p/l/uploadpro/htdocs/index.php on line 37והוא מביא לי die בלי קשרכתובת האתר (עדיין בבניה)http://uploadpro.host2.nu/והקוד:<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "[url]http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">[/url]<html xmlns="[url]http://www.w3.org/1999/xhtml"[/url] xml:lang="en" lang="en"><html><head><link rel="stylesheet" type="text/css" href="style.css" /><title>Uplaod-Pro</title></head><body><div class="wrapper"><div class="box"><ul><li><a href="index.php">ראשי</a></li><h2>העלאת תמונות</h2><form action="" method="post" enctype="multipart/form-data"><p><label for="file">בחר קובץ:</label> <input type="file" name="userfile" id="file"> <br><br><button>העלה!</button><p>*יש לעלות עד 2 מ"ב(MB)<br>*רצוי ששם הקובץ יהיה באנגלית כדי שלא יהיו בעיות<br><?php // Configuration - Your Options $allowed_filetypes = array('.jpg','.gif','.bmp','.png'); // These will be the types of file that will pass the validation. $max_filesize = $max_filesize = 2000000; // Maximum filesize in BYTES (currently 2.0MB). $upload_path = './files/'; // The place the files will be uploaded to (currently a 'files' directory). $filename = $_FILES['userfile']['name']; // Get the name of the file (including file extension). $ext = substr($filename, strpos($filename,'.'), strlen($filename)-1); // Get the extension from the filename. // Check if the filetype is allowed, if not DIE and inform the user. if(!in_array($ext,$allowed_filetypes)) die('The file you attempted to upload is not allowed.'); // Now check the filesize, if it is too large then DIE and inform the user. if(filesize($_FILES['userfile']['tmp_name']) > $max_filesize) die('The file you attempted to upload is too large.'); // Check if we can upload to the specified path, if not DIE and inform the user. if(!is_writable($upload_path)) die('You cannot upload to the specified directory, please CHMOD it to 777.'); // We'll start handling the upload in the next step if(move_uploaded_file($_FILES['userfile']['tmp_name'],$upload_path . $filename)) echo 'Your file upload was successful, view the file <a href="' . $upload_path . $filename . '" title="Your File">here</a>'; // It worked. else echo 'There was an error during the file upload. Please try again.'; // It failed?><br></div></div></form></head>
פורסם 2008 בספטמבר 1317 שנים תשנה את ה id כך שהוא יהיה זהה ל name, יש סיכוי שזה יעבוד לך.<input type="file" name="userfile" id="file">
פורסם 2008 בספטמבר 1317 שנים מחבר בדקתי בגוגל מזה Undefined indexוזה אומר שמשתנה לא קיים מזאת אומרת?(הבנתי שהוא לא קיים אז מה עושים?)
פורסם 2008 בספטמבר 1317 שנים אני לא מבין מה כל כך מסובך במה שרשמתי לך.תחליף את השורה הזו:<input type="file" name="userfile" id="file"> עם השורה הזו:<input type="file" name="userfile" id="userfile"> אתה צריך גם להבין את הקוד שאתה שם באתר שלך במקום רק סתם להעתיק אותו.המשתנה $_FILES הוא מערך ששומר את כל הנתונים מהשדות שהם file והוא מתייחס לתגית ID של אותו אובייקט ולא ל name.תמיד שאתה יוצר איזה אובייקט תוודא שה name ו id יהיו זהים.מקווה שעכשיו זה ברור יותר.
פורסם 2008 בספטמבר 1317 שנים חח, עכשיו אני רואה מה הבעיה האמיתית פה (חוץ מהקודמת).אתה רושם את כל הקוד שאמור לטפל בקובץ שהועלה באותו עמוד שאתה מבקש מהמשתמש להעלות את הקובץ.מן הסתם המשתנה FILES ריק כי עדיין לא בוצע ה Submit.יש לך 2 אופציות:א. להעביר את קוד ה php לקובץ חדש ולשנות את ה action של ה form לאותו קובץ.ב. להכניס את כל הקוד של ה php ל if שבודק אם קיים המשתנה הזו ( isset ) או להעביר לו משנה אחר שידע להיכנס לקוד.
פורסם 2008 בספטמבר 1417 שנים 3. ליצור תגית input מסוג hidden ובקוד ה PHP לבדוק אם הוא קיים.אגב, הקוד אמור לעבוד בצורה כזאתי, אומנם תיהיה שגיאה בפעם הראשונה שנכנסים לדף, אך ברגע שיהיה submit הכל יעבוד כשורה ולא יהיה שום שגיאה (בתנאי שהקוד תקין, וכנראה שהוא לא).
פורסם 2008 בספטמבר 1817 שנים מחבר תודה שניסיתם רק עוד שאלה איך מכניס את הקישור של התמונה בתוך text areaואני רוצה לשים אותו בתוך וראיציות שונות של קישור לדוגמא :שיהיה בקוד לקישור לפורומים ולקוד HTML וקוד ישיר!אני מאוד אודה לכם
ארכיון
דיון זה הועבר לארכיון ולא ניתן להוסיף בו תגובות חדשות.