21-04-2009, 19:47
|
מנהל
|
|
חבר מתאריך: 26.07.08
הודעות: 6,473
|
|
אוקי אז בוא נעשה קצת סדר:
זה הפלט של פונקציית var_dump על המערך $_FILES:
קוד:
array(1)
{
["file"]=> array(5)
{
["name"]=> string(11) "2rcvfci.jpg"
["type"]=> string(24) "application/octet-stream"
["tmp_name"]=> string(23) "C:\xampp\tmp\php716.tmp"
["error"]=> int(0)
["size"]=> int(0)
}
}
(אם היית מעתיק את פלט פונקציית var_dump מקוד המקור של האתר, היית יכול לראות זאת מסודר יפה בצורה הנ"ל)
כפי שניתן לראות, הגודל של התמונה (size) זה 0, והשגיאה (error) היא גם 0.
זה ניראה לי די מוזר.
בקוד של ה-HTML אפשר לראות שאתה מתייחס לקובץ המועלה באמצעות המילה "file", ולא באמצעות המילה "userfile", ראה:
קוד:
<input type="file" name="file" id="file" />
לכן זה לא נכון להשתמש במערך:
כי הוא ריק.
אלא נכון להשתמש במערך:
כי זה השם (name) שציינת בטופס ה-HTML.
נסה להריץ את קוד ה-PHP הבא, ותגיד מהן התוצאות:
קוד PHP:
$cfg = array('file_uploads', 'upload_max_filesize', 'post_max_size', 'max_input_time');
echo '<br /><br />';
foreach($cfg as $v)
echo $v,': ', ini_get($v),'<br />';
echo '<br /><br />';
בנוסף, מה הגודל של קובץ התמונה שאתה מנסה להעלות?
אחרון ולא חביב במיוחד, למה לא הוספת את קוד ה-HTML הבא בתוך הטופס:
קוד:
<input type="hidden" name="MAX_FILE_SIZE" value="30000" />
(ניתן כמובן לשינוי בהתאם לצרכיך)
שים לב כאן:
http://www.php.net/manual/en/featur...post-method.php
מה אומרים על האלמנט MAX_FILE_SIZE:
ציטוט:
The MAX_FILE_SIZE hidden field (measured in bytes) must precede the file input field, and its value is the maximum filesize accepted by PHP. Fooling this setting on the browser side is quite easy, so never rely on files with a greater size being blocked by this feature. The PHP settings for maximum-size, however, cannot be fooled. This form element should always be used as it saves users the trouble of waiting for a big file being transferred only to find that it was too big and the transfer failed.
|
שים לב לחלק המודגש באדום.
מסתבר לבסוף שלא קראת היטב?
|