jje Posted August 12, 2011 Posted August 12, 2011 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 outputs0 Any help appreciated; Thanks!
Guest Geoff Posted August 12, 2011 Posted August 12, 2011 echo the value of $_FILES['uploadedfile']['tmp_name'] and post it here.
Guest Geoff Posted August 12, 2011 Posted August 12, 2011 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.
jje Posted August 12, 2011 Author Posted August 12, 2011 Thanks! 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 phpxn046Xit returns no results.
jje Posted August 12, 2011 Author Posted August 12, 2011 I tried that and here's what happened: [root@server /]# ls /tmp/phpxn046X ls: /tmp/phpxn046X: No such file or directory
jje Posted August 16, 2011 Author Posted August 16, 2011 Yes [root@server /]# lldrwxrwxrwt 5 root root 4096 Aug 16 10:57 tmp My script location is /home/user1/uploadmedia.php
jje Posted August 27, 2011 Author Posted August 27, 2011 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! Closing after nearly a month of attempts
Recommended Posts