Jump to content

File upload problems on my VPS


jje

Recommended Posts

Hi there! Recently I purchased a virtual server to give me more power and disk space and I installed Kloxo/LXAdmin on my server. However, I am currently having a few issues with PHP uploads. After posting on the VPS provider's community IRC channel four times, I still can't get this issue solved. So I thought I'd try to ask you experts on HelioNet to see if you can help me out.

 

I'm having trouble with file uploads (PHP); I'm trying to make a script where the user can upload files to the server. I've used this script before on my XAMPP install, but on my VPS I am unsuccessful. I am using an if statement to see if the file move was a success, but it is returning false and an error code of 0. According to the PHP website this means success, even though the file isn't there and the if statement returns false.

I'm really stumped, and I was wondering if anybody could help me out. :)

 

Here's my code:

 

<?php
if (!isset($_POST['submit'])) { ?>
<form action="upload.php" method="post"
enctype="multipart/form-data">
<label for="uploadedfile">Filename:</label>
<input type="file" name="uploadedfile" id="file" /> 
<br />
<input type="submit" name="submit" value="Submit" />
</form>
<?php
}else{

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

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "work";
}else{
    echo $_FILES['uploadedfile']['error'];
}

}

 

And it outputs

0

 

Any help appreciated; Thanks! :D

Link to comment
Share on other sites

Take this part of your code out:

 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "work";
}else{
    echo $_FILES['uploadedfile']['error'];
}

 

Add this in:

 

echo $_FILES['uploadedfile']['tmp_name'];

 

Then see if the temporary file exists.

Link to comment
Share on other sites

Thanks! :D I tried that and it outputted

/tmp/phpxn046X

 

However, I don't think that path exists, since when I login to SSH and try

[root@server /]# locate phpxn046X

it returns no results.

Link to comment
Share on other sites

  • 2 weeks later...

Woo hoo! I have finally worked it out! I enabled display_errors in my PHP configuration that showed me the error. Then I did some research on the error, and it appears that the uploadfile.php and uploads/ had the wrong directory - it only worked with permissions of 0777.

 

Thanks for your help, xaav! :D

 

Closing after nearly a month of attempts :lol:

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
×
×
  • Create New...