Forum Moderators: coopster

Message Too Old, No Replies

uploading files using a switch

         

dkin

7:11 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



I have this code.

function movform()
{
global $link;
echo '<form action="addcon.php?op=movieinsert" method="post">'
. 'Movie Name: <input type="text" name="movname" /><br>'
. 'Movie Description: <input type="text" name="movdesc" /><br>'
. 'Movie Size: <input type="text" name="movsize" /><br>'
. 'Choose a file to upload: <input name="uploadedfile" type="file" /><br>'
. 'Movie Length: <input type="text" name="movlength" /><br>'
. 'Movie Type: <select name="movtype"><option value="trailer">trailer</option><option value="teaser">teaser</option><option name="gameplay">gameplay</option></select><br>';
$result = mysql_query("SELECT * FROM reviews order by title asc", $link) or die ("query 1: " . mysql_error());

echo 'Game Name: <select name="gameid">';
while ($row = mysql_fetch_array($result))
{
echo '<option value="'.$row['id'].'">'.$row['title'].'</option>';
}
echo '</select><br>'
. '<input type="submit" value="Insert Movie"/>';
}

function movin()
{
global $link, $row, $movname, $movdesc, $movsize, $uploadedfile, $movlength, $movtype, $gameid;

$target_path = "/gs/vids/";

$target_path = $target_path . basename( $_FILES['$uploadedfile']['name']);

if(move_uploaded_file($_FILES['$uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['$uploadedfile']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}

$result = mysql_query("INSERT INTO vids (gameid, title, description, size, length, type) VALUES ('$gameid', '$movname', '$movdesc', '$movsize', '$movlength', '$movtype')", $link);

if (isset($result))
{
echo '<center>Movie Inserted</center>';
echo $target_path;
}
else
{
echo '<center>Insert Failed please go back and reinsert this movie</center>';
}
movform();
}

I dont know why but I keep getting the error There was an error uploading the file, please try again!

Anyone know how I can fix this?

ChadSEO

8:16 pm on Jul 12, 2005 (gmt 0)

10+ Year Member



I seem to remember having problems along these lines at one point. They were resolved by adding the following attribute to the form tag:
enctype="multipart/form-data"

So, the one line in your code would look like:

echo '<form action="addcon.php?op=movieinsert" method="post" enctype="multipart/form-data">'

dkin

5:21 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



Its still not working,

there must be something wrong with this

$target_path = "/gs/vids/";

$target_path = $target_path . basename( $_FILES['$uploadedfile']['name']);

if(move_uploaded_file($_FILES['$uploadedfile']['tmp_name'], $target_path)) {
echo "The file ". basename( $_FILES['$uploadedfile']['name']). " has been uploaded";
} else{
echo "There was an error uploading the file, please try again!";
}

But I cant find it.

Anyone?

dreamcatcher

6:08 pm on Jul 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Hi dkin,

ChadSEO was right, you need that syntax in your upload form.

I think the problem is this variable:

$_FILES['$uploadedfile']['name']

Using the superglobal $_FILES means that this variable is available throughout the scope of your program and that includes inside functions. It doesn`t need to be declared as a global variable.

Try simply:

$_FILES['uploadedfile']['name']

$_FILES['uploadedfile']['tmp_name']

etc

dc

dkin

6:20 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



I have tried those also, nothing happens lol. I suck at this whole uploading thing.

dreamcatcher

8:12 pm on Jul 13, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



hee hee. Does your directory have write permissions?

ChadSEO

9:17 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



haha dreamcatcher, didn't think about that one, and definitely a likely candidate.

dkin

11:52 pm on Jul 13, 2005 (gmt 0)

10+ Year Member



yes I tried chmoding it to 777 but Im not sure what is a safe chmod.

What should I chmod it?

ChadSEO

2:23 pm on Jul 14, 2005 (gmt 0)

10+ Year Member



777 will work for testing, but you certainly don't want to leave it that way. The best way to do it would be to chgrp the directory to the group that apache runs under, and chmod 775. At least, this is how I usually do it, somebody else might have another suggestion.

dkin

5:00 pm on Jul 14, 2005 (gmt 0)

10+ Year Member



It only seems to wrok with chmod 777 775 is not working, what can I do?

ChadSEO

5:24 pm on Jul 14, 2005 (gmt 0)

10+ Year Member



chmod 775 will ownly work if the group that apache runs under is the same group that "owns" that directory.

If you look in your httpd.conf file for apache for a directive called "Group", this will tell you the group that apache runs under. Alternatively, you can do

ps -ef ¦ grep httpd ¦ grep -v grep
from a command line, and this will tell you the user that apache runs under - the group usually has the same name (ie httpd/httpd, nobody/nobody, etc.).

Then, you will need to do a chgrp <apachegroup> /path/to/upload/folder, for example:

chgrp nobody /var/www/public_html/upload

dkin

5:20 pm on Jul 15, 2005 (gmt 0)

10+ Year Member



I dont even know where to find my httpd.conf file.

Is there any other way to do this?

ChadSEO

5:54 pm on Jul 15, 2005 (gmt 0)

10+ Year Member



httpd.conf files are usually in /etc/httpd/httpd.conf or /usr/local/apache/conf/httpd.conf.