PDA

View Full Version : بدست آوردن آدرس فایل از طریق fileUpload



ali_mnkt
سه شنبه 17 فروردین 1389, 20:54 عصر
با سلام خدمت دوستان

من می خوام مسیر یک فایل روی client رو از طریق fileUpload بدست بیارم.از دستور زیر استفاده

می کنم .

FileUpload1.PostedFile.FileName

اما این دستور فقط اسم فایل رو می ده و مسیرش رو نمی ده در صورتی که باید مسیر فایل رو

بده دوستان کسی می تونه بگه مشکل کجاست یا راه حل دیگه ای هست یا نه ؟

Peyman.Gh
سه شنبه 17 فروردین 1389, 23:55 عصر
در IE.6.0 مسیر فایل را هم نشان میدهد.

iman_ad
چهارشنبه 18 فروردین 1389, 00:32 صبح
برای چی باید مسیر فایل کاربر نشون بده به چه درد می خوره؟

ali_mnkt
چهارشنبه 18 فروردین 1389, 10:23 صبح
در IE.6.0 مسیر فایل را هم نشان میدهد.

من در IE هم امتحان کردم ولی باز نشون نمی ده البته در خود FileUpload آدرس فایل رو نشون

می ده ولی من با دستور FileUpload1.PostedFile.FileName نیاز دارم که مسیر فایل رو در یک

متغییر string بریزم ولی فقط نام فایل و پسوند اون رو نشون می ده !!!!!!!!! کجای کار ایراد داره ؟

Peyman.Gh
چهارشنبه 18 فروردین 1389, 19:29 عصر
به احتمال 99 % شما نمیتوانید به مسیر فایل دسترسی داشته باشید.

Vahid_moghaddam
چهارشنبه 18 فروردین 1389, 19:35 عصر
منطقی نیست که شما بتونید به آدرس فایل دسترسی داشته باشید. از نظر امنیت جالب نیست.

Peyman.Gh
چهارشنبه 18 فروردین 1389, 19:40 عصر
چرا از نظر امنیت جالب نیست ؟!

Vahid_moghaddam
چهارشنبه 18 فروردین 1389, 19:56 عصر
چرا از نظر امنیت جالب نیست ؟!

There is no way to do this from a web-browser*. Java, Flash and Silverlight will not allow your code to access the local file system. Silverlight and Flash allow you to use the open file dialog, but you can't get the full path of the selected file. This is a standard security precaution - you don't typically want a website to have access to your file system!

The file upload trick works in IE, until you upgrade to IE7/8 and disable the "Include local directory path when uploading files to a server" option. Also, you will be uploading the file to the server every time, which wastes bandwidth and CPU at both ends since you're not doing anything with the file.
The client's local path wouldn't be much use to you anyway, unless your server is on the same network.
* Unless you use a custom ActiveX control in IE, which is a horrible option IMHO.

http://forums.asp.net/p/1170634/1959688.aspx

Vahid_moghaddam
چهارشنبه 18 فروردین 1389, 20:02 عصر
در قسمت File Upload Control در لینک زیر نوشته شده:


Historically, the HTML File Upload Control (<input type=file>) has been the source of a significant number of information disclosure vulnerabilities. To resolve these issues, two changes were made to the behavior of the control.
To block attacks that rely on “stealing” keystrokes to surreptitiously trick the user into typing a local file path into the control, the File Path edit box is now read-only. The user must explicitly select a file for upload using the File Browse dialog.


Additionally, the “Include local directory path when uploading files” URLAction has been set to "Disable" for the Internet Zone. This change prevents leakage of potentially sensitive local file-system information to the Internet. For instance, rather than submitting the full path C:\users\ericlaw\documents\secret\image.png, Internet Explorer 8 will now submit only the filename image.png.



http://blogs.msdn.com/ie/archive/2008/07/02/ie8-security-part-v-comprehensive-protection.aspx

Peyman.Gh
چهارشنبه 18 فروردین 1389, 20:04 عصر
من متوجه نشدم که مثلاً اگر C:\Admin\decoder\test.txt را بدست بیاریم چه ایرادی دارد ؟

General-Xenon
جمعه 20 فروردین 1389, 11:05 صبح
سلام....!
اینم کدش.....


string filepath = System.IO.Path.GetFullPath(FileUp1.FileName);


امیدوارم بدردت بخوره....:چشمک:

Peyman.Gh
جمعه 20 فروردین 1389, 12:31 عصر
سلام....!
اینم کدش.....


string filepath = System.IO.Path.GetFullPath(FileUp1.FileName);
امیدوارم بدردت بخوره....:چشمک:

دوست عزیز شما خودتان امتحان کردید ؟!!!!!!!!!
این دستور سمت سرور میباشد !

خروجی در زمان اجرا در لوکال به این صورت میباشد : C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Your File

پس چه ربطی دارد ؟! لطفاً دوستان را گمراه نکنید.

alireza_s_84
جمعه 20 فروردین 1389, 13:10 عصر
دوست عزیز شما خودتان امتحان کردید ؟!!!!!!!!!
این دستور سمت سرور میباشد !

خروجی در زمان اجرا در لوکال به این صورت میباشد : C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\Your File

پس چه ربطی دارد ؟! لطفاً دوستان را گمراه نکنید.
من با شما موافقم در سمت سرور اصلا نمیتونید اینکار رو انجام بدین. ولی با جاوا اسکریپت در سمت کلاینت میشه اینکار رو انجام داد:
یک فیلد Hidden قرار بدین و با استفاده از جاوا سمت کلاینت مسیر فایل رو در این فیلد ذخیره کنید:


<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default3.aspx.cs" Inherits="Default3" %>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Untitled Page</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<script type="text/javascript">
function SetPath()
{
var path = document.getElementById('FilePath').value;
document.getElementById('<%= HiddenField1.ClientID %>').value = path;
alert(document.getElementById('<%= HiddenField1.ClientID %>').value);
}
</script>

<asp:HiddenField ID="HiddenField1" runat="server" />
<input onchange="SetPath()" id="FilePath" type="file" />

</div>
</form>
</body>
</html>

ali_mnkt
دوشنبه 23 فروردین 1389, 00:09 صبح
من سیستم ارسال ایمیل برای مدیر سایت گذاشتم و مدیر باید بتونه قابلیت ارسال

ایمیل با فایل ضمیمه رو داشته باشه خوب من حالا نیاز دارم که مدیر بتونه یه فایل رو از روی کامپیوترش انتخاب کنه و به ایمیلش

اضافه کنه خوب من فقط می خام آدرس فایل انتخاب شده روی کامپیوترش رو بدست بیاره

در کد های ارسال ایمیل برای Attach کردن یک فایل به اون از کد زیر استفاده می کنم


mail.Attachments.Add(new Attachment("c:\\temp\\example3.txt"));

خوب حالا من نیاز دارم که آدرس فرضی c:\\temp\\example3.txt رو مدیر برای Attach کردن یک فایل از روی سیستمش انتخاب کنه

که قاعدتا باید یک چیزی مثل openFileDialog باشه که بتونه فایل رو از روی سیستمش انتخاب کنه خوب من فکر کردم بهترین چیز

FileUpload هست که وقتی brows رو میزدی می تونستی از رو سیستم یک فایل انتخاب کنی و با کد زیر هم آدرس اون فایل انتخاب شده

رو می تونیم بدست بیاریم


ّFileUpload1.PostedFile.FileName


اما با این کد در سیستم خودم فقط اسم فایل با پسوندش رو می ده ( نه مسیر فایل) اما رو یه سیستم دیگه امتحان کردم مسیر فایل

رو هم می ده ( من رو سیستم خودم هم با IE و هم با FireFox امتحان کردم)پس به نظرم روش قابل اطمینانی نیست حالا میخوام بدونم

شما روش دیگه ای سراغ ندارید ؟ یا این که می تونید بگید مشگل این روش چیه ؟