Saving file to disk

hey,

i have this code for savinf a file to disk.

def SaveFiletoDisk(file, object)
	folder = "mediastorage"
	root_dir = Dir.new(folder)
	current_dir = folder + "/" + object.id.to_s
	Dir.mkdir(current_dir)
	File.open(current_dir, "wb") { |f| f.write(file.read) }
	return current_dir
end

and i get errors like:

Permission denied - mediastorage/12

how can i set the permission for the folder “12” so that i can save a
file in it?

Thx

how can i set the permission for the folder “12” so that i can save a
file in it?

Hi Nick,

How you do it is OS specific, but what you do is generally one of the
following.

You can ensure that your web server runs under the same user id as the
owner of that directory. You can also set up a group, give that
directory group write access, and then ensure that the user id that
your web server is running under is in the same group as the owner of
that directory. (I typically use this approach.) Finally, you can
give that directory world write access.

(You might also consider using an absolute path. Not that that will
fix the permissions issue.)

Zachary H. wrote:

how can i set the permission for the folder “12” so that i can save a
file in it?

Hi Nick,

How you do it is OS specific, but what you do is generally one of the
following.

You can ensure that your web server runs under the same user id as the
owner of that directory. You can also set up a group, give that
directory group write access, and then ensure that the user id that
your web server is running under is in the same group as the owner of
that directory. (I typically use this approach.) Finally, you can
give that directory world write access.

(You might also consider using an absolute path. Not that that will
fix the permissions issue.)

it doesnt seem to work :s:s

Permission denied - F:/rails_template_0.0.2/mediastorage/38/

i use win xp

i can create \mediastorage
i can create \mediastorage\38

but not the file itself :s:s

Can u help me?

Thx

On Sep 1, 2006, at 10:41 AM, Nick B. wrote:

def SaveFiletoDisk(file, object)
folder = “mediastorage”
root_dir = Dir.new(folder)
current_dir = folder + “/” + object.id.to_s
Dir.mkdir(current_dir)
File.open(current_dir, “wb”) { |f| f.write(file.read) }
return current_dir
end

Can u help me?

It looks like you’re naming the directory to write to, but you’re not
naming the file. Does this help?

File.open("#{current_dir}/filename.ext", “wb”) { |f| f.write
(file.read) }

Zachary H. wrote:

On Sep 1, 2006, at 10:41 AM, Nick B. wrote:

def SaveFiletoDisk(file, object)
folder = “mediastorage”
root_dir = Dir.new(folder)
current_dir = folder + “/” + object.id.to_s
Dir.mkdir(current_dir)
File.open(current_dir, “wb”) { |f| f.write(file.read) }
return current_dir
end

Can u help me?

It looks like you’re naming the directory to write to, but you’re not
naming the file. Does this help?

File.open("#{current_dir}/filename.ext", “wb”) { |f| f.write
(file.read) }

thx that works! :slight_smile: