Question about PHP upload page

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
awdio
Forum Newbie
Posts: 5
Joined: Fri Oct 27, 2006 5:42 pm

Question about PHP upload page

Post by awdio »

feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]


I'm trying to develop a simple Flash video upload site for a client and I've run into something I haven't really dealt too much with: an automated user upload page.  I'm starting off at the simplest level by just trying to make a page that lets you upload a file up to a 100k, and its giving me back errors.  I'm guessing this may be because I need to activate some sort of permission on my web space to be able to write, but it also might be something with the code.

Here's what I have made so far with uploader.php:

Code: Select all

<?php
// Where the file is going to be placed 
$target_path = "uploads/";

/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
$_FILES['uploadedfile']['tmp_name'];  

$target_path = "uploads/";

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

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    echo "The file ".  basename( $_FILES['uploadedfile']['name']). 
    " has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}
?>
By the way, the script was taken from: [url]http://www.tizag.com/phpT/fileupload.php?MAX_FILE_SIZE=100000 [/url]

I've tried modifying the $target_path to go to the exact path of the site and not go into the uploads folder, but the folder before that which is "fullScreen".

The result of choosing a file and uploading is "Warning: move_uploaded_file(uploads/Buzzy Beetle.gif): failed to open stream: Permission denied in /home/vectors/public_html/fullScreen/uploader.php on line 14"

and..

'Warning: move_uploaded_file(): Unable to move '/tmp/phpzjYA8l' to 'uploads/Buzzy Beetle.gif' in /home/vectors/public_html/fullScreen/uploader.php on line 14
There was an error uploading the file, please try again!"

If you want to see and try the upload page for yourself, it's right here.

Thanks!


feyd | Please use

Code: Select all

,

Code: Select all

and [syntax="..."] tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read:  [url=http://forums.devnetwork.net/viewtopic.php?t=21171]Posting Code in the Forums[/url] to learn how to do it too.[/color]
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

If you add the following after the last time $target_path is set, is it a valid path?

Code: Select all

echo getcwd() . DIRECTORY_SEPARATOR . $target_path;
awdio
Forum Newbie
Posts: 5
Joined: Fri Oct 27, 2006 5:42 pm

Post by awdio »

Sorry I wish I knew the terminology, but I don't understand what you mean by "set". Is what you mean by set is when you set what $target_path equals? For exaple on 10:

Code: Select all

$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);
Or is it here:

Code: Select all

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
But where exactly would you put the suggested code? Can you show me an example?

Thanks
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Place the snippet between those two lines.
awdio
Forum Newbie
Posts: 5
Joined: Fri Oct 27, 2006 5:42 pm

Post by awdio »

Alright, thanks. This is what I get:

/home/vectors/public_html/fullScreen/uploads/Buzzy Beetle.gif
Warning: move_uploaded_file(uploads/Buzzy Beetle.gif): failed to open stream: Permission denied in /home/vectors/public_html/fullScreen/uploader.php on line 14

Warning: move_uploaded_file(): Unable to move '/tmp/php1ToZkl' to 'uploads/Buzzy Beetle.gif' in /home/vectors/public_html/fullScreen/uploader.php on line 14
There was an error uploading the file, please try again!

Its telling me its putting it in /home/vectors/public_html/fullScreen/uploads/Buzzy Beetle.gif which is where I want it to go.

Edit: But wait it looks like a permission problem, yet it's still happening even if I turn on the execute permission..So so far I have read write and execute all checked.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

What's the permissions number that the directory has? It should look like 0777 or 0755.
awdio
Forum Newbie
Posts: 5
Joined: Fri Oct 27, 2006 5:42 pm

Post by awdio »

777
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

So, just to make sure, /home/vectors/public_html/fullScreen/uploads/ has 0777 set?
awdio
Forum Newbie
Posts: 5
Joined: Fri Oct 27, 2006 5:42 pm

Post by awdio »

I checked them all. Set to 777. Tried the form last night, didn't work. Today it worked!!! What?! Does this mean it takes some amount of time for it to work after permissions are changed? I just dont understand. Thanks for your help because I wouldn't of known to do this without your suggestion.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Usually the change is immediate, however it's possible your browser was using a cached result.
Post Reply