[SOLVED] PHP File Upload

This is a discussion on "[SOLVED] PHP File Upload" within the PHP Forum section. This forum, and the thread "[SOLVED] PHP File Upload are both part of the Program Your Website category.



Go Back   Webforumz.com > Main Forums > Program Your Website > PHP Forum

Notices


Closed Thread
 
LinkBack Thread Tools
  #1 (permalink)  
Old Nov 26th, 2007, 00:58
Highly Reputable Member
Join Date: Sep 2007
Age: 15
Posts: 717
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
[SOLVED] PHP File Upload

Hello everyone,
I have been following several threads about file uploading using php, but I can't figure out how to do it correctly. I have tried several tutorials and all of them end the same way: Error, no success
Here is my form:
HTML: Select all
<form enctype="multipart/form-data" action="upload_file.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
Choose a file: <input name="uploadedfile" type="file" />
<input type="submit" value="Upload File" />
</form>
This submits the file to upload_file.php, which looks like this:
PHP: Select all

<?php
$target_path 
"uploads/";
$target_path $target_path basename$_FILES['uploadedfile']['name']); 

if(
move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo 
"The file has been uploaded";
} else{
    echo 
"There was an error uploading the file, please try again!";
}
?>
It all looks fine! Now, I tried this out, but it gave me the following errors:
Quote:
Warning: move_uploaded_file(uploads/arrow.jpg) [function.move-uploaded-file]: failed to open stream: Permission denied in /opt/www/cport80/swagner/upload_file.php on line 13

Warning: move_uploaded_file() [function.move-uploaded-file]: Unable to move '/var/tmp/phpNbaWem' to 'uploads/arrow.jpg' in /opt/www/cport80/swagner/upload_file.php on line 13
There was an error uploading the file, please try again!
And line 13 contains:
PHP: Select all

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) { 

(Also in the full code above ^). I have no idea why this is happening. I'm quite good at PHP, and I don't see any errors in my code. I think the problem is that my server has this feature disabled, since it says "permission denied", or maybe the connection to the server can't be made... I don't know.

A common error is that the directory is missing. But not in this case, I have created the directory "uploads" on my site...

Any suggestions? Feel free throw anything at me since I understand PHP very well...

Cheers
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)

  #2 (permalink)  
Old Nov 26th, 2007, 01:08
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: PHP File Upload

Have you changed the chmod of the directory you are uploading to?
It will need to be 0777. This can be done easily via Cpanel's file manager and other file managers.
In Cpanel you must highlight the directory and select "change permissions".
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
  #3 (permalink)  
Old Nov 26th, 2007, 01:09
Highly Reputable Member
Join Date: Sep 2007
Age: 15
Posts: 717
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP File Upload

I don't have a server with CPanel. Everything is done through FTP as it's a university server (the site is for a professor there).
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
  #4 (permalink)  
Old Nov 26th, 2007, 01:14
alexgeek's Avatar
Technical Administrator

SuperMember
Join Date: Jul 2007
Location: Webforumz 24/7
Age: 15
Posts: 3,770
Blog Entries: 9
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to alexgeek
Re: PHP File Upload

Oh damnit, I can't remember the way to do it via FTP (or if there is one).
Let me have a google for a min.
Last Blog Entry: 3D Chess in your browser! (Mar 14th, 2008)
  #5 (permalink)  
Old Nov 26th, 2007, 01:15
Highly Reputable Member
Join Date: Sep 2007
Age: 15
Posts: 717
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP File Upload

I'm not sure you can do it with FTP... I just meant that I have no direct control over the server. So, I can't change permissions...
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
  #6 (permalink)  
Old Nov 26th, 2007, 05:37
saltedm8's Avatar
Lead Administrator

SuperMember
Join Date: Nov 2005
Location: Always About
Age: 27
Posts: 1,298
Blog Entries: 1
Thanks: 1
Thanked 6 Times in 6 Posts
Re: PHP File Upload

i use smart ftp, and all i do is highlight the folder/file then right click on the file or folder i want and the option is there ( maybe its something like that )
__________________
My Recipe forum...don't click here
Last Blog Entry: Basic Advice for newbies (Feb 1st, 2008)

Last edited by saltedm8; Nov 26th, 2007 at 05:39.
  #7 (permalink)  
Old Nov 26th, 2007, 12:49
Highly Reputable Member
Join Date: Sep 2007
Age: 15
Posts: 717
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP File Upload

Nope, nothing there... I use a weird program: FileZilla
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
  #8 (permalink)  
Old Nov 26th, 2007, 13:43
c010depunkk's Avatar
SuperMember

SuperMember
Join Date: Apr 2007
Location: Willich, Germany
Age: 20
Posts: 593
Blog Entries: 2
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to c010depunkk
Re: PHP File Upload

In FileZilla: right-click on the folder --> File attributes and set all the check boxes or set the numeric value to 777.
  #9 (permalink)  
Old Nov 26th, 2007, 16:09
Reputable Member
Join Date: Oct 2007
Location: Liverpool UK
Age: 29
Posts: 216
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP File Upload

Is this the same as uploading a image to a folder, instead of in a database?? If so i have a some working script i could post you?
  #10 (permalink)  
Old Nov 26th, 2007, 22:31
Reputable Member
Join Date: Apr 2007
Location: Scotland
Age: 17
Posts: 233
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Blake121
Re: PHP File Upload

I'm not totally sure, but I think you'd have to give the full path to the image folder. Not just "/uploads". So I think

PHP: Select all

$target_path "uploads/"
Should become

PHP: Select all

$target_path "/opt/www/cport80/swagner/uploads/";
// change this to the full path to your destination folder.
// I'm guessing it's what's above 
Try that and see if it works.

Blake.
  #11 (permalink)  
Old Nov 26th, 2007, 23:01
Highly Reputable Member
Join Date: Sep 2007
Age: 15
Posts: 717
Blog Entries: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Re: PHP File Upload

Thanks everyone, but c010depunkk's solution worked perfectly. The code now works since I changed the folder's permissions.

Thread Solved
Last Blog Entry: Windows Vista vs. Mac Leopard (Nov 4th, 2007)
Closed Thread

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
PHP+SQL+File Upload joshlindem PHP Forum 5 May 10th, 2008 16:48
file upload berry05 Job Opportunities 0 Mar 19th, 2008 19:09
[SOLVED] File Upload Possibly Blocked longstand PHP Forum 2 Jan 31st, 2008 23:20
File Upload magiccupcake PHP Forum 1 Jan 22nd, 2007 05:10
File upload djme PHP Forum 4 Jan 11th, 2006 18:25


All times are GMT. The time now is 20:42.


Powered by vBulletin®
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.2.0 RC8
© 2003-2008 Webforumz.com : All Rights Reserved

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43