צפיות
תשובות
אני חייב עזרה בהעלת קבצים לשרת
קיבלתי מחברת האחסון שלי קובץ שמעלה קבצים לשרת, ואני יפשתי בקוד באיזו שורה אני מכניס את הכתובת של התקייה שבה אני רוצה לאחסן את הקובץ (לבנתיים הוא מעלה את הקובץ לתקייה שבה נמצאת הסקריפט ואני רוצה לעלות אותה לתקייה אחרת בשרת שלי). אולי מישהו יכול לעזור ולומר לי איפה אני אמור להכניס את שורת הכתובת של התקייה
הנה הקוד: (מצטער על האורך)
if (Request.TotalBytes == 0) Response.End;
// set maximum filesize to 1 Mb
var maxFileSize = 1024 * 100000;
// use recordset to cast binary to string, and split result on seperator
var recordSet = Server.CreateObject("ADODB.Recordset");
recordSet.fields.append(0, 201, Request.TotalBytes);
recordSet.open();
recordSet.addNew();
recordSet.fields(0).appendChunk(Request.binaryRead(Request.TotalBytes));
var data = new String(recordSet.Fields(0)).split((recordSet.Fields(0) + "").substring(0, (recordSet.Fields(0) + "").indexOf("rn")));
recordSet.close();
// store values and files in different objects, so we can scan through them later
var values = {};
var files = {};
for (var i = 1; i < data.length – 1; i++) {
var curdata = data[i].split("rn");
if ((curdata[2].length == 0) && (curdata[4].length == 0)) values[curdata[1].substring(38, curdata[1].length-1)] = curdata[3];
if ((curdata[2].length != 0) && (curdata[4].length != 0) && (data[i].length < maxFileSize)) files[curdata[1].replace(/.*filename=['"](.*)['"]/, "$1").replace(/([^\]+\)+/,"")] = { contentType:curdata[2].substr(14), fileData:curdata.slice(4, curdata.length – 1).join("rn")};
}
// scan through the names in the values object and show each corresponding value
for (var fieldName in values) Response.Write(fieldName + " = " + values[fieldName] + "<br/>");
// scan through the files object, store each file to disk, and show the result (images show directly, other data show the contenttype as a hyperlink to a popupwindow)
for (var fileName in files) {
try {
var fso = new ActiveXObject("Scripting.FileSystemObject");
var file = fso.OpenTextFile(Server.MapPath(fileName), 2, true);
file.write(files[fileName].fileData);
file.close();
Response.Write(fileName + " : <a href='"+fileName+"' target='_new'><img align='top' src='"+fileName+"' title='"+files[fileName].contentType+"' border=" onerror='this.parentNode.innerHTML=this.title'/></a>123456<br/>");
} catch(e) {
Response.Write("Error. Could not upload the file: " + fileName + "<br/>");
}
}
4 תשובות
כנראה שבשורה הזו.
var file = fso.OpenTextFile(Server.MapPath(fileName), 2, true);
זה לא זה… אוף
ניסיתי להכניס את השורה הבאה:
var file = fso.OpenTextFile(Server.MapPath("e: 161131324946user330966\image"+fileName+), 2, true);
וזה לא עובד לי אין לי מושג למה, אולי למישהו יש קוד נורמלי להעלת קבצים, היה לי קוד מצוין אבל כשהעברתי שרת הוא לא עובד לי בשרת החדש ואין לי הרבה זמן לעבוד על זה אז אני מתחנן לעזרה שמישהו יעזור לי תודה.
שני דברים:
א) לא עובד זה לא תיאור של בעיה. קרא איך מציגים שאלה.
ב) קודים מוכנים זה לא בבית ספרנו. בשביל זה יש גוגל.
פתרון
תכניס את הקובץ שאיתו אתה מעלה את הקבצים לתיקיה עצמה !