Problems with images/file and dir creation

software development

#1

I’m new to DreamHost and have a web site set up to allow users to upload images and store them to be viewed later.

I currently create a directory from my PHP scripts to put the images for a user in, then put their images in that directory. However, it doesn’t look like I can do that on DreamHost. I have the site working locally and it used to work on my old hosting service. Now the directories just don’t appear.

I’ve tried changing file permissions as well, with no success.

If there’s a way to do this on DreamHost, please let me know.

Also, the bigger issue might be that I have a flawed approach to storing and displaying uploaded files. If there’s a better approach, please let me know. I could put the image data in a database entry, but how do I display it after, especially if I can’t move the data to a file?

Thanks!


#2

Did you develop the PHP scripts yourself?

Are you getting any error messages?

Are you attempting to create the directories in a different home directory than the CGI user?

Is PHP running as CGI or a module?

I don’t have any problems doing this with Perl. But then again Perl is not executed by a wrapper that adds additional security restrictions.

:cool: [color=#6600CC]Atropos[/color] | openvein.org


#3

[quote] Did you develop the PHP scripts yourself?

Are you getting any error messages?

Are you attempting to create the directories in a different home directory than the CGI user?

Is PHP running as CGI or a module?

I don’t have any problems doing this with Perl. But then again Perl is not executed by a wrapper that adds additional security restrictions. [/quote]

I developed the scripts myself. I had them tested and running on another hosting service as well as my local machine.

I did get error messages that the file couldn’t be written to the directory. The directory creation didn’t seem to cause an error message.

The directories are in the same home directory as my login user. I think my site is running under CGI, because it seems that all PHP is set up that way for new users on DreamHost.

Thanks!


#4

The following works for me.<?php $parent_dir = realpath($_SERVER['DOCUMENT_ROOT'] . '/test'); echo "<p>Parent Directory is $parent_dir</p>"; $dir = $parent_dir . '/test' . mt_rand(1, 1000); $result = mkdir($dir, 0777); echo "<p>Result: $result</p>"; ?>

:cool: [color=#6600CC]Atropos[/color] | openvein.org


#5

Thanks! I’ll give it a shot.


#6

Turns out that my problem is that I was using a base directory path I set in a configuration file. I messed up that setting, which threw everything else off.

I’m going to try out the $_SERVER[‘DOCUMENT_ROOT’] variable instead. That way I won’t have to change my config on a new server. You’ve helped out a ton.

On another note, is it safe to leave dirs writeable under my website directory? I’m not sure how else to do it right now.

My solution is to create directories for each user on the fly and put their files in that directory. Then the files are ready for viewing right away. If anyone knows if storing them in a DB or something is better, feel free to respond.

I am very impressed with the speed of the responses I’ve gotten in this forum, as well as from DH tech support. Thanks again to everyone!


#7

Storing them in a database is not a good idea. Besides the increased overhead it would be a pain to backup and restore.

In my example I should have said 0755 for the permissions. The default umask is 0022, and so with my example the permissions ended up as 0755 anyways. You definitely should not grant public write permissions, especially to web accessible directories.

:cool: [color=#6600CC]Atropos[/color] | openvein.org


#8

Hey, thanks for the info. Everything is at 755 now.