Wrox Programmer Forums
|
Beginning PHP Beginning-level PHP discussions. More advanced coders should post to the Pro PHP forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Beginning PHP section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old June 8th, 2004, 07:45 AM
Authorized User
 
Join Date: Jan 2004
Posts: 78
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to Ashleek007
Default file upload error

hi, ive used this method many times before to upload pictures to a folder on my remote host but this time it aint wrkin!

this is the error i get: -
Warning: Unable to create 'upload_files/tentphoto2.jpg': Permission denied in /www.classicjoineryweb.co.uk/upload.php on line 75
{line 74,75,76 shown below)


Warning: Unable to move '/tmp/phpBvZc1i' to 'upload_files/tentphoto2.jpg' in /www.classicjoineryweb.co.uk/upload.php on line 75
Somthing is wrong with uploading a file.

heres the lines of upload code i use: -

<?php
$site_name = $_SERVER['HTTP_HOST'];
$url_dir = "http://".$_SERVER['HTTP_HOST'].dirname($_SERVER['PHP_SELF']);
$url_this = "http://".$_SERVER['HTTP_HOST'].$_SERVER['PHP_SELF'];

$upload_dir = "upload_files/";
$upload_url = $url_dir."/upload_files/";
$message ="";

//create upload_files directory if not exist
//If it does not work, create on your own and change permission.
if (!is_dir("upload_files")) {
    die ("upload_files directory doesn't exist");
}

if ($_FILES['userfile']) {
    $message = do_upload($upload_dir, $upload_url);
}
else {
    $message = "Invalid File Specified.";
}

print $message;

function do_upload($upload_dir, $upload_url) {

    $temp_name = $_FILES['userfile']['tmp_name'];
    $file_name = $_FILES['userfile']['name'];
    $file_type = $_FILES['userfile']['type'];
    $file_size = $_FILES['userfile']['size'];
    $result = $_FILES['userfile']['error'];
    $file_url = $upload_url.$file_name;
    $file_path = $upload_dir.$file_name;

    //File Name Check
    if ( $file_name =="") {
        $message = "Invalid File Name Specified";
        return $message;
    }
    //File Size Check
    else if ( $file_size > 500000) {
        $message = "The file size is over 500K.";
        return $message;
    }
    //File Type Check
    else if ( $file_type == "text/plain" ) {
        $message = "Sorry, You cannot upload any script file" ;
        return $message;
    }
:)line 73
    $result = move_uploaded_file($temp_name, $file_path);
    $message = ($result)?"File url <a href=$file_url>$file_url</a>" :
              "Somthing is wrong with uploading a file.";
:)line 76
    return $message;
}
?>

any ideas why im getting these errors?
ive got a feeling it could be somthing to do with the permissions ive got to my server and to uploading stuff to it? dont see why i would havre any problems though?!

cheers
ASH

__________________
My new web design domain
www.askmultimedia.co.uk
 
Old June 8th, 2004, 10:17 AM
Friend of Wrox
 
Join Date: Jun 2003
Posts: 256
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Yes. Sounds like it's a permissions problem. PHP needs the right to write the file into your destination directory - and PHP usually runs as 'nobody', and nobody ain't got no rights!

Have you chmod 777 your destination directory?

(I actually usually run a cron job to move files out of /tmp/ into my target folder on a set schedule, so that the job can run under the PID of a proper user and your directory can thus have proper permissions applied to it. This is a bit of a hack, though, since it isn't going to be good enough if you need the files moved immediately, and there's probably a better way that I haven't thought of.)

Take it easy
Dan
 
Old June 8th, 2004, 05:44 PM
richard.york's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

Hi Ashlee,
Here's an FAQ that I wrote for setting permissions:
http://p2p.wrox.com/topic.asp?TOPIC_ID=11962

There's a method demonstrated in there that's a little more secure than chmod 777, if you have the ability to preform chown commands. And of course if you have any more questions, let us know.

HTH!



Regards,
Rich

::::::::::::::::::::::::::::::::::::::::::
The Spicy Peanut Project
http://www.spicypeanut.net
::::::::::::::::::::::::::::::::::::::::::





Similar Threads
Thread Thread Starter Forum Replies Last Post
File upload error balesh.mind ASP.NET 2.0 Professional 2 August 20th, 2007 02:52 PM
Upload File With ActiveFile Error yeapjudy Classic ASP Basics 0 June 15th, 2007 03:56 AM
Filter File Types in ASP.NET File Upload ramuis78 ASP.NET 2.0 Basics 2 May 31st, 2007 10:50 AM
Whole Folder upload(Multi file Upload) ramasamy_rams XML 1 September 9th, 2005 12:43 PM
JSP file upload and delete file pandjie JSP Basics 0 January 29th, 2005 10:49 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.