>Here is the error I'm receiving when attempting to upload a file....
>Warning: Unable to create 'temp/test.txt': Permission denied in
>/home/.../www/website/upload3.php on line 11
>..could it be that my web host isn't giving me permissions to upload
>files ?

Yes.  Or at least not where you are trying to put the file...

Give us the first 11 lines of upload3.php please.

It's possible that you simply need to create a world-writable directory for
your uploads.

Do *NOT* *NOT* *NOT* *NOT* *NOT* *NOT* *NOT* create that world-writable
directory *INSIDE* your "web" directory (or htdocs, or where-ever it is that
you are putting your HTML files).

Did you catch that?  It's really important that you not have world-writable
directories in your web server tree...

When you FTP (or SCP, or SSH) in to your account, what do you see *FIRST*?

If it's something like this:


Then you should create a new directory called "incoming" (or "uploads" or
whatever) there so you see:.


Note that "uploads" is *NOT* inside of "htdocs" but "next to" it.

Then, make *that* directory world-writable.  (Use your FTP software or from
SSH/telnet do):

chmod 777 uploads

*THEN*, alter your PHP script to upload the files to there:

$path = "/full/path/to/uploads";
if (move_uploaded_file($file, "$path/$file_name")){
  # Do *everything* you can think of here to be sure
  # "$path/$file_name" is totally kosher, and is not
  # some hacker binary or porn or whatever you don't
  # want on your server.
  # Once you *know* it's kosher, insert the path into a MySQL table:
  $query = "insert into kosher_uploads (path) values ('$file_name')";
  mysql_query($query) or error_log(mysql_error()); #Check HTTP error log for
  echo "Upload failed!";

Then, in a separate script, in a "cron" job (read "man 5 crontab") you can

  $upload = "/full/path/to/uploads";
  $destination = "/full/path/to/where/you/really/wanted/it/";
  $query = "select path from kosher_uploads";
  # It's a cron job that will send *YOU* email, so it's okay to print MySQL
  $paths = mysql_query($query) or print(mysql_error());
  $moved = array();
  while (list($path) = mysql_fetch_row($paths)){
    if (rename("$upload/$path", "$destination/$path")){
      $moved[] = $path;
  $goners = implode("', '", $moved;
  $query = "delete from kosher_uploads where path in ('$goners')";
  mysql_query($query) or print(mysql_error());

The first script does not deal well with filename "collisions"
IE, What if *TWO* people upload "Britney.JPEG" at the same time.
(Assuming you want to allow JPEG upload in the first place.)
(And that you don't want to rule out anything named Britney on principle.)

All this code is just typed in, untested...  But the ideas are sound.  YMMV.

If the real problem is that the upload *ITSELF* is trying to create
temp/test.txt (I think not) then you need to dig into php.ini and/or
.htaccess an alter the file_upload_dir and get that to be a directory that
PHP user can write to (again, a world-writable directory *NOT* inside your
web-tree).  Your ISP may or may not have chosen to make this impossible for
you to do.  No way to tell with the info you've given so far...  Asking the
ISP would be faster/easier on that one.

Like Music?  http://l-i-e.com/artists.htm

PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

Reply via email to