Forum Moderators: coopster

Message Too Old, No Replies

Uploading files

Help with permissions

         

Birdman

8:22 pm on Jan 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hello all,

I'm experimenting with uploading files from a web page using the form and script below. I'm getting permission denied. Could anyone tell me how to set or gain the permission?

<form enctype="multipart/form-data" action="upload.php" method="post">
<input type="hidden" name="MAX_FILE_SIZE" value="30000">
Send this file: <input name="userfile" type="file">
<input type="submit" value="Send File">

And in upload.php

<?php
$uploaddir = '/var/www/uploads/';

print "<pre>";
if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploaddir . $_FILES['userfile']['name'])) {
print "File is valid, and was successfully uploaded. Here's some more debugging info:\n";
print_r($_FILES);
} else {
print "Possible file upload attack! Here's some debugging info:\n";
print_r($_FILES);
}

?>

Birdman

9:20 pm on Jan 28, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Got it working.

RussellC

10:28 pm on Jan 28, 2003 (gmt 0)

10+ Year Member



Speaking of Uploading Files. I understand how to do it in PHP, but how would someone link an uploaded file with an item in a mySQL database. I am very interested in doing this. All i need to do is have someone upload a very large txt file and link it to a 'customer number' in my DB. I dont want to actually upload it into the mySQL database though. Is that possible?

Thanks

mole

10:34 pm on Jan 28, 2003 (gmt 0)

10+ Year Member



well, the database needs to have a field like "url_of_uploaded_file" then the upload script saves the file into a directory of uploaded files and writes / updates a record in the database.

RussellC

10:35 pm on Jan 28, 2003 (gmt 0)

10+ Year Member



OK, thats quite easy. Thanks for the help.

RussellC

6:14 pm on Jan 29, 2003 (gmt 0)

10+ Year Member



I got this to work and now I will need it to upload some big files. It works with smaller files but will not work with the big files. I immediately get a Page cannot be displayed error if the file size is larger than say 500k.

I set post_max_size to like 200M and and upload_max_filesize to the same in the php.ini. Is there something I am missing to upload very large text files?

my script looks like this:

if ($userfile!= "" ¦¦ $userfile!= NULL) {
$upfile = "/var/www/html/filelistings/" . $HTTP_POST_FILES['userfile']['name'];
$upfile2 = $HTTP_POST_FILES['userfile']['name'];
copy($HTTP_POST_FILES['userfile']['tmp_name'], $upfile);
$filesql = "UPDATE jobs SET filelistings = '$upfile2' WHERE jobnumber = $jobnumber";
if (@mysql_query($filesql)) {
echo("Done");
}
}

RussellC

8:11 pm on Jan 29, 2003 (gmt 0)

10+ Year Member



OK, I fixed it! I am gonna post how just for the record.

This was more of a RedHat 8.0 issue. If you have Redhat 8 installed and your php installation was part of the initial install of the OS, Redhat installs a php.conf file in /etc/httpd/conf.d/ that basically overwrites the max file size in php.ini and sets it to 512k.

I don't know why they did this but I am glad I finally figured it out. Just for the archives.

-Russell

jatar_k

8:12 pm on Jan 29, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



good little tip RussellC, thanks