Reply to topic
Upload file through php
libonati


Joined: 02 Sep 2008
Posts: 1
Reply with quote
Hello,
I'm trying to upload files through php.
I really don't understand where is the mistake.
I've set 777 permission to files folder.

Below there are few lines of code I've used to test the upload.
Do you notice some errors?

I'm on a linux builder plus plan.
Thank you in advance for any help.
Luca

Code:
<?php

if(isset($_FILES['uploaded'])){
$target = "vservers/mysite/htdocs/upload/files/".basename($_FILES['uploaded']['name']) ;
print_r($_FILES);

if(move_uploaded_file($_FILES['uploaded']['tmp_name'],$target)) echo "OK!";

}
else{
 echo "<form enctype='multipart/form-data' action='index.php' method='POST'>";
 echo "File:<input name='uploaded' type='file'/><input type='submit' value='Upload'/>";
 echo "</form>";
}


?>
mgwalk


Joined: 04 Sep 2008
Posts: 3
Reply with quote
Can you look in your error.log file Question
For the error and line number.
cburns


Joined: 03 Feb 2008
Posts: 2
Location: Newark, DE
Reply with quote
Try placing another forwardslash in front of vservers, so it looks like:

$target = "/vservers/mysite/htdocs/upload/files/".basename($_FILES['uploaded']['name']);

PHP may be trying to place the file into the wrong directory.

You may want to try toning the permissions down to 755. We run PHP under suexec so that the scripts will run as your specific user. Suexec REALLY doesn't like 777 permissions and has a tendency to freak out when they are set like that.

If those don't work, open a ticket with us if you haven't already. We can give you access to your logs if you don't already have it and we can point you in the right direction. We're always here to help Very Happy
msdi


Joined: 22 Aug 2007
Posts: 3
Reply with quote
Also, move_uploaded_file() will set the file permissions to 0600. If you plan on letting users access files directly (as opposed to through a redirect script), then you'll want to set the permissions with chmod() after it's copied.
darnold


Joined: 17 Mar 2005
Posts: 25
Reply with quote
Also, move_uploaded_file() will set the file permissions to 0600. If you plan on letting users access files directly (as opposed to through a redirect script), then you'll want to set the permissions with chmod() after it's copied.


I don't believe this is a problem on HMS servers. I've seen other people mention it but I have plenty of working examples uisng move_uploaded_file without said permission issue. It may be a problem with servers that do not run php as a cgi with suexec.

I'm pretty sure cburn nailed it. The first / slash represents the root of the server. Without it php will think you are giving it a relative path starting from vservers and that is not going to exist.
Upload file through php
You can post new topics in this forum
You can reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
All times are GMT  
Page 1 of 1  

  
  
 Reply to topic