Jump to content

Recommended Posts

Posted

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

Posted

echo the value of $_FILES['uploadedfile']['tmp_name'] and post it here.

Posted

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.

Posted

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.

Posted

What if you try

ls /tmp/phpxn046X

?

Posted

I tried that and here's what happened:

 

[root@server /]# ls /tmp/phpxn046X
ls: /tmp/phpxn046X: No such file or directory

Guest Geoff (Xaav)
Posted

Is your /tmp folder chmoded to 777?

Posted

Yes :)

 

[root@server /]# ll

drwxrwxrwt  5 root root 4096 Aug 16 10:57 tmp

 

My script location is /home/user1/uploadmedia.php

  • 2 weeks later...
Posted

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:

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