Jump to content


Photo

Question: PHP upload page help


  • Please log in to reply
10 replies to this topic

#1 awdio

awdio
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 October 2006 - 10:49 PM

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:

<?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: http://www.tizag.com...LE_SIZE=100000

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!

#2 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 27 October 2006 - 10:53 PM

You would need to alter the permissions on the uploads folder to allow writing.

#3 Skatecrazy1

Skatecrazy1
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 27 October 2006 - 10:57 PM

try
<?php
//where you want the files 2 go
$dir = "uploads/";
 if( ($_FILES['file']['name'] != "" ) && ($_FILES['file']['size'] < 102400))
  {
    copy($_FILES['file']['tmp_name'], "$dir".$_FILES['file']['name'])  or die("Couldn't upload .swf");
} else { die("Error:  You either didn't specify a file, or the file is too large.  Please try again."); }
?>

fuck it or fight it

#4 awdio

awdio
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 27 October 2006 - 11:08 PM

I modified the code and tried uploading a 4k gif file and got the error back "Error: You either didn't specify a file, or the file is too large. Please try again."

All read and write permissions were all checked including world.

I also want to point out that I've tried a 4k swf and increased the file size of what it is aloud to upload.  For now, I want to create something that would successfully upload anything, then worry about altering the script so it would ignore everything except certain files.

#5 Skatecrazy1

Skatecrazy1
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 28 October 2006 - 12:02 AM

okay well this script here should upload any file.
<?php
//where you want the files 2 go
$dir = "uploads/";
 if( $_FILES['file']['name'] != "" )
  {
    copy($_FILES['file']['tmp_name'], "$dir".$_FILES['file']['name'])  or die("Couldn't upload .swf");
} else { die("Error:  You either didn't specify a file."); }
?>

fuck it or fight it

#6 tobydeh

tobydeh
  • New Members
  • Pip
  • Newbie
  • 7 posts
  • LocationLondon -UK

Posted 28 October 2006 - 12:09 AM

Definately not shibby

You should always use "is_uploaded_file($_FILES['userfile']['tmp_name'])" as a bare minimum security check. Also in the last comment The example used "Copy()"... Not a good idea. it again doesnt check if the file was uploaded via HTTP POST.


look at the following example:

<?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(is_uploaded_file($_FILES['uploadedfile']['tmp_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!";
}
}
?>
There are many ways to skin a cat!

#7 awdio

awdio
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 October 2006 - 12:44 AM

I used the copy script anyways and I got this: "Error: You either didn't specify a file." 

Then I looked at Tobbydeh's example and even tried it.  Still out of luck.  Anyone want to test and try their php upload to see if it works for them?

#8 gmwebs

gmwebs
  • Members
  • PipPipPip
  • Advanced Member
  • 174 posts
  • LocationLondon

Posted 28 October 2006 - 09:59 AM

Well when I tried your script, I was still getting permission denied. You may have checked that the rights are correct, but what about the owner of the folder? The script will never work until you sort out your permissions/ownership...

#9 Skatecrazy1

Skatecrazy1
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 28 October 2006 - 04:56 PM

chmod your uploads folder to 777
fuck it or fight it

#10 awdio

awdio
  • New Members
  • Pip
  • Newbie
  • 4 posts

Posted 28 October 2006 - 07:11 PM

Strangely enough the uploads folder, the uploader.php and the folder that contains all of these all have 777 for their permissions.

Edit: 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 all your help though.  I wouldn't of known to do this in the first place.

#11 Skatecrazy1

Skatecrazy1
  • Members
  • PipPipPip
  • Advanced Member
  • 126 posts
  • LocationSouthern California

Posted 28 October 2006 - 08:00 PM

no probably just something got restarted when you logged in in the morning.
fuck it or fight it




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users