Jump to content

file upload


corillo181

Recommended Posts

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..
[code]<?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());


}
?>[/code]
Link to comment
Share on other sites

[!--quoteo(post=371047:date=May 3 2006, 01:20 PM:name=Richard181)--][div class=\'quotetop\']QUOTE(Richard181 @ May 3 2006, 01:20 PM) [snapback]371047[/snapback][/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...
Link to comment
Share on other sites

this is the view file code
[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].'">';

}
?>[/code]

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..
Link to comment
Share on other sites

[!--quoteo(post=371053:date=May 3 2006, 01:33 PM:name=Richard181)--][div class=\'quotetop\']QUOTE(Richard181 @ May 3 2006, 01:33 PM) [snapback]371053[/snapback][/div][div class=\'quotemain\'][!--quotec--]
this is the view file code
[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].'">';

}
?>[/code]
[/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
Link to comment
Share on other sites

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....
Link to comment
Share on other sites

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 [i]is[/i] there and you [i]can[/i] download it and it [i]does[/i] 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.
Link to comment
Share on other sites

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..

Link to comment
Share on other sites

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..[code]<?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;

}
}
?>[/code]
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.