Forum Moderators: coopster

Message Too Old, No Replies

Image Uploading in PHP by Browser...

Images don't appear in FTP program after uploading through browser.

         

jatses

1:07 am on Mar 24, 2005 (gmt 0)

10+ Year Member



I'm working on a php script that will upload an image to the server through the browser. Everything uploads great and all my pages can call/access/view the images with no problems. However, when I am in my ftp program, WSFTP, I cannot "see" the images I uploaded through the browser. When I try to delete the folder it says that it is not empty. How can it not be empty when nothing appears to be in there, but yet how can nothing appear in there when pages are pulling images from that folder. I'm curious as to why this is happening. It didn't use to happen at the freebie host I had, only after I switched hosts and servers. Here is my code I use to upload the files, is something wrong with it that could be causing this:

<?php

if(substr_count($_SERVER["QUERY_STRING"], "uploadfile") >=1 && $submit) {

/*--------------------------------------------------*/

MYSQL_CONNECT($db_host,$db_username,$db_password);
MYSQL_SELECT_DB($database);

/*--------------------------------------------------*/

PRINT ("<FORM ACTION='$_SERVER[PHP_SELF]?uploadfile' NAME='uploadfile' METHOD='post' AUTOCOMPLETE='off' ENCTYPE=\"multipart/form-data\">
<TABLE CLASS='formtable'>
<TR>
<TD CLASS='formtable'>File:</TD><TD CLASS='formtable'><INPUT CLASS='login' TYPE='FILE' NAME='upload_file' ACCEPT='image/*'><BR></TD>
</TR>
<TR>
<TD CLASS='formtable'>Category:</TD>
<TD CLASS='formtable'>
<SELECT CLASS='login' NAME='upload_category'>
<OPTION VALUE=''>Category...
<OPTION VALUE='gallery'>Gallery
<OPTION VALUE='equipment'>Equipment
<OPTION VALUE='personnel'>Personnel<BR>
</SELECT>
</TD>
</TR>
<TR>
<TD CLASS='formtable'>&nbsp;</TD>
<TD CLASS='formtable'>
<INPUT CLASS='login' TYPE='SUBMIT' NAME='submit' VALUE='Upload'>&nbsp;
<INPUT CLASS='login' TYPE='RESET' NAME='reset' VALUE='Clear'>
</TD>
</TR>
</TABLE>
</FORM>");

/*--------------------------------------------------*/

MYSQL_CLOSE();

/*--------------------------------------------------*/

} elseif(substr_count($_SERVER["QUERY_STRING"], "uploadfile") >=1 && $submit) {

/*--------------------------------------------------*/

MYSQL_CONNECT($db_host,$db_username,$db_password);
MYSQL_SELECT_DB($database);

/*--------------------------------------------------*/

if(!empty($_FILES[upload_file])) {
$uploaddir = "../../images/$upload_category/";
$upload_name = $_FILES["upload_file"]["name"];
if (move_uploaded_file($_FILES[upload_file][tmp_name], $uploaddir . $_FILES[upload_file][name])) {
$query = ("INSERT INTO `gallery` (`imagepath`, `imagename`) VALUES ('$upload_category', '$upload_name');");
$result = MYSQL_QUERY($query);
PRINT ("<CENTER>The file $upload_name was successfully uploaded!</CENTER>");
} else {
PRINT ("<CENTER>The file $upload_name failed to upload!</CENTER>");
}
}

/*--------------------------------------------------*/

MYSQL_CLOSE();

/*--------------------------------------------------*/

?>

wrightee

7:56 am on Mar 24, 2005 (gmt 0)

10+ Year Member



When you upload through the browser, the file is being processed by the user that PHP runs under (e.g. Apache). When you upload through FTP you are under your own username. The permissions on the server are what is preventing you from seeing the pics; change those and you should be fine.

jatses

5:25 pm on Mar 29, 2005 (gmt 0)

10+ Year Member



How do I change the permissions? Is that through CHMOD? It is on an Apache server if that helps at all. I haven't the slightest clue how to access the permissions, but I'll mess around with it and post back if I figure it out. Thanks for helping.

jatses

jusdrum

5:40 pm on Mar 29, 2005 (gmt 0)

10+ Year Member



The ideal way would be to use php's chmod() function and apply it to the file after you upload it. Permissions set to 755 should allow you to see it.

...after uploading...
chmod($uploaddir . $_FILES[upload_file][name],0755);

Hope this helps!

dcrombie

8:57 am on Mar 30, 2005 (gmt 0)



Surely 0644 permissions are enough - you don't need to make uploaded files executable ;)

jatses

6:39 pm on Mar 30, 2005 (gmt 0)

10+ Year Member



Thanks for the information, but how do I change permissions on the files I have already uploaded? Thanks for helping!

jatses