Jump to content


Photo

file upload


  • Please log in to reply
7 replies to this topic

#1 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 03 May 2006 - 08:20 PM

i'm using this code to upload files to my database and a directory.. bu the problem is that once is uploaded, the picture comes out as a FORBIDDEN view file..
<?php
$uploadDir = 'xml/';

if(isset($_POST['upload']))
{
$fileName = $_FILES['userfile']['name'];
$tmpName = $_FILES['userfile']['tmp_name'];
$fileSize = $_FILES['userfile']['size'];
$fileType = $_FILES['userfile']['type'];

$filePath = $uploadDir . $fileName;

$result = move_uploaded_file($tmpName, $filePath);
if (!$result) {
echo "Error uploading file";
exit;
}

include 'config/db.php';


if(!get_magic_quotes_gpc())
{
$fileName = addslashes($fileName);
$filePath = addslashes($filePath);
} 

$query = "INSERT INTO upload2 (name, size, type, path ) ".
"VALUES ('$fileName', '$fileSize', '$fileType', '$filePath')";

mysql_query($query) or die(mysql_error());


}
?>


#2 todd3834

todd3834
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 03 May 2006 - 08:26 PM

[!--quoteo(post=371047:date=May 3 2006, 01:20 PM:name=Richard181)--][div class=\'quotetop\']QUOTE(Richard181 @ May 3 2006, 01:20 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
picture comes out as a FORBIDDEN view file..
[/quote]

the forbidden error usually comes up when you are trying to view a directory with no index file. ie: "www.mywebsite.com/blah" but the folder blah has no index file and folder browsing is not allowed.

In order to help you, we are going to need to see the code you are using to display the image as well...

#3 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 03 May 2006 - 08:38 PM

this is the view file code
<?php
include 'config/db.php';
$q = 'SELECT name FROM upload2';
$getpic=mysql_query($q);
while($row=mysql_fetch_array($getpic))
{
echo'<img src="xml/'.$row[name].'">'; 

}
?>

i read something about setting file uolaod permission with chomd and se tit to 0777, but i don't know how to set up the code or where to put it..

chomd("path/file",0777);..something like that..

#4 todd3834

todd3834
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 03 May 2006 - 08:39 PM

[!--quoteo(post=371053:date=May 3 2006, 01:33 PM:name=Richard181)--][div class=\'quotetop\']QUOTE(Richard181 @ May 3 2006, 01:33 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
this is the view file code
<?php
include 'config/db.php';
$q = 'SELECT name FROM upload2';
$getpic=mysql_query($q);
while($row=mysql_fetch_array($getpic))
{
echo'<img src="xml/'.$row[name].'">'; 

}
?>
[/quote]

Exactly! :) It is trying to view a folder that does not exist on the server. "xml/filename". The problem is you are not including the file extention. You must enter some code to determin the file type and supply the correct extention (ie: .jpg or .gif). With the file extention it will no longer send them to browse a directory that does not exist

#5 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 03 May 2006 - 08:48 PM

i don't think is that .. i think the problem is in the upload form.. becuase when i upload a file name to the data base and i uploa it to the directory with ftp it works just fine.. with the same cod i just showed you.. but when i up loading it with the script i just showed you.. and i go to chekc out the picture.. it says forbidden..

so i assume the problem has to be in the upload process, if the code works with ftp up loaded files....

#6 todd3834

todd3834
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 03 May 2006 - 09:01 PM

Ok, well to narrow down the problem. Test your upload script, after you upload a file use a ftp client to browse to the file that should have been uploaded. If it is there, download it via FTP and see if it generates and error when you try to open it. If it is not there, then your upload script is obviously not transfering the file. If it is there and it doesn't open fine, then we are going to have to look a little closer at your upload script because obviously something is going wrong. If it is there and you can download it and it does open just fine, its of course an error in the display script, most likely the extention.

Please check this out first, if there is an error with the upload script I will look a little closer at it in a couple hours... I am in class right now so I am kind of limited to what I can do to help.

If you have not changed the file permisions of the folder yet, that is also something that will probably cause you trouble with your upload script. In your FTP client try browsing to the folder you are uploading the images, select it and see if your FTP client has the feature to change permisions. In dreamweaver you can right click a folder and change the permisions through the FTP client. If your FTP client doesn't offer that feature, then if you have a control panel that you can log into, there may be a file manager utility in there. Most likely you will be able to browse to the folder and change the permisions from there as well.

#7 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 03 May 2006 - 09:23 PM

yes i use dreamweaver for my as my ftp client.. and the folder permission is set to 777 wich mean anyone can view it..

and i did try the 2 ways..


with ftp - the scrip works

with the upload script - it does not work only sends the forbidden..

so i know it must be the upload method..



#8 corillo181

corillo181
  • Members
  • PipPipPip
  • Advanced Member
  • 896 posts

Posted 04 May 2006 - 05:44 AM

well i found out the problem it had to be copy insted of move..

but now can someone tell me how do i work a file chekc in to this becuase i try few ways and still not workin..
<?php
$uploaddir =  'xml/';
if(isset($_POST['ulfile']))
{
if($_SERVER['ulfile']['type'] == "image/gif"){
$filename = $_FILES['ulfile']['name'];
$tmpname = $_FILES['ulfile']['tmp_name'];
$filesize = $_FILES['ulfile']['size'];
$filetype = $_FILES['ulfile']['type'];
$filepath = $uploaddir . $filename;
$result=copy($tmpname, $filepath);
}
if(!$result){
echo"error uploading file";
exit;

}
}
?>





0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users