XILO Community Forum

Support 0845 034 6444 • Sales 0800 084 2421

  (#1 (permalink)) Old
Dom Dom is offline
User
Dom is on a distinguished road
 
Dom's Avatar
 
Posts: 83
Join Date: Sep 2005
Location: UK
Default PHP Settings Help - 25/10/2006, 8:34 PM

Hi all,

I've been writing a PHP script that should let the user upload small files to a directory. The trouble is, it doesn't work. I've had some people look at it and they dont seem to think that there's anything wrong with it, so I was wondering if there might be any default PHP settings that might affect the script.

I dont know much about the different PHP settings (or how to change them) but I thought you guys might know. The permissions on the upload folder are set to 755, so that should allow people to upload files.

I've attached the code in a text file for you to look at if it helps.

Thanks a lot,

- Dom

Reply With Quote
  (#2 (permalink)) Old
Dom Dom is offline
User
Dom is on a distinguished road
 
Dom's Avatar
 
Posts: 83
Join Date: Sep 2005
Location: UK
Default Re: PHP Settings Help - 25/10/2006, 8:34 PM

Sorry, here's the code.

Attached Files
File Type: txt code.txt (1.9 KB, 36 views)
Reply With Quote
  (#3 (permalink)) Old
Techie & Moderator
Kieran is on a distinguished road
 
Kieran's Avatar
 
Posts: 769
Join Date: Apr 2006
Location: Swindon, UK
Default Re: PHP Settings Help - 25/10/2006, 11:16 PM

Well, the problem with your attached code is some of it is missing

I can't see anything directly wrong with whats there but for the fact some of the variables are contained in an include file you didn't attach.

As it stands though the only thing I will say is that any errors won't be to do with chmod as the destination directory will be owned by the username used in the other file to connect via ftp so that shouldn't cause any issues.

Settings wise, what size of file are you trying to upload? 2Mb is the limit and if you want more you need to set this with a custom php.ini file in the same directory as your script.

If you post the other file (with passwords etc. removed of course) I can advise further.

Last edited by Kieran; 25/10/2006 at 11:22 PM.
Reply With Quote
  (#4 (permalink)) Old
Techie & Moderator
Kieran is on a distinguished road
 
Kieran's Avatar
 
Posts: 769
Join Date: Apr 2006
Location: Swindon, UK
Default Re: PHP Settings Help - 26/10/2006, 12:27 AM

Ok, here is some quick dirty code that should work (decided to knock you up a non-ftp solution )

The HTML bit:
PHP Code:
<form action="upload.php" method="post" enctype="multipart/form-data">
<
input name="source_file" type="file" />
<
input type="submit" value="Upload" title="Upload your file" />
</
form
The PHP bit:
PHP Code:
<?php

// Into a variable the file array goes
$source $_FILES["source_file"];
        
// Grab the file name from the array
$source_name $_FILES["source_file"]["name"];

// Grabe the file it's self (well its location) from the array
$source_file $_FILES["source_file"]["tmp_name"];

if (
copy ($source_file"/home/your_user_name/public_html/_uploads/$source_name")) 
{
      
# Return true
      
echo "Upload successful!";
}
else 
{
      
# Return failure
      
echo "Upload failed!";
}
?>
You might want to add some checking to that (file sizes etc.) and you will also need to chmod the destination directory to 777 but that should work fine. Feel free to ask for any more help you might need.
Reply With Quote
  (#5 (permalink)) Old
Dom Dom is offline
User
Dom is on a distinguished road
 
Dom's Avatar
 
Posts: 83
Join Date: Sep 2005
Location: UK
Default Re: PHP Settings Help - 26/10/2006, 4:51 PM

That's fantastic, thanks a lot Kieran.

I didn't forget to include some of the code though, it only contained my username and password anyway! I thought it best not to post it.

As for file size, I was trying to upload a text file that said "hello" so it was well within the 2Mb limit.

Thanks for your help though, I'll try it tonight. Hopefully all will be good.

One quick question though. Where you've got the 'copy' function, will I need to change the destination path? I thought that the destination path would be relative to where the PHP script is, but from what I can tell the path "/home/your_user_name/public_html/_uploads/$source_name" is relative from the root directory (or something lol).

So if I had the PHP script in a folder called 'scripts' and wanted to upload the file to a subdirectory called 'uploads', would the destination path look like "/uploads/$source_file" or would I have to keep all of the "/home/your_user_name/public_html/..." parts as well.

Sorry I'm sure you've got better things to do, but just thought I'd ask.

Reply With Quote
  (#6 (permalink)) Old
Techie & Moderator
Kieran is on a distinguished road
 
Kieran's Avatar
 
Posts: 769
Join Date: Apr 2006
Location: Swindon, UK
Default Re: PHP Settings Help - 26/10/2006, 6:11 PM

Yup, I noticed that the code was in fact all there but after I made my post, it was a long day yesterday, lol

Yes is the short answer, you do need the direct and full path, so if your scripts directory was in your html root and the upload directory inside that you would need the following path:

/home/username/public_html/scripts/uploads/$source_file

Hope this helps

PS: I have moved this discussion out of the support area and into general as its more a coding question
Reply With Quote
  (#7 (permalink)) Old
Dom Dom is offline
User
Dom is on a distinguished road
 
Dom's Avatar
 
Posts: 83
Join Date: Sep 2005
Location: UK
Default Re: PHP Settings Help - 26/10/2006, 8:52 PM

Excellent job!

Thanks again, it works perfectly now. I think the only problem I had was that the folder permissions were set to 755 and not 777. Also, I've found that when I use the ftp_put() function as opposed to the 'copy' function, I dont need to have the long-winded destination path. It's simply "/my_domain/my_folder/uploads/" or whatever.

Again, thanks for all your help, this was getting really frustrating!

Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes


Similar Threads
Thread Thread Starter Forum Replies Last Post
Domain-wide antispam/virus checking settings solaris Support Queries 5 08/06/2007 5:01 PM
Changing DNS settings to XILO jamesw4 Support Queries 4 15/03/2007 10:57 AM


Powered by vBulletin | XHTML | © Copyright 2003-2008 XILO Communications Ltd. All rights reserved. E&OE