Solved

Uploading images

Posted on 2004-09-16
4
171 Views
Last Modified: 2006-11-17
How come I keep getting no files specified ? how do I figure out the path. If thats the problem. This page is on my website where my sites hosted too.

<?php
if($file_name !="") {
copy ("$file", "/usr/local/root/$file_name")
        or die("Could not Copy the File");
            }
            else {die("No Files Specified"); }
            ?>
            <html><head><title>Upload Complete</title></head>
            <body><h3>File upload succeeded...</h3>
            <ul>
            <li>Sent: <?php echo "$file_name"; ?>
            <li>Size: <?php echo "$file_size"; ?>
            <li>Type: <?php echo "$file_type"; ?>
            </ul>
            <a href="<?php echo "$file_name" ?> ">
                                         Click Here to View File</a>
                                                       </body>
                                                       </html>
0
Comment
Question by:smphil
  • 2
4 Comments
 
LVL 5

Expert Comment

by:darksinclair
ID: 12080985
Do you have "enctype='multipart/form-data'" in your form tag?  This is required to post files.

also, here is an upload function you could try using :

function upload_file()
{

        //file too big
        if($_FILES['userfile']['size']>$_POST['MAX_FILE_SIZE'] || !$_FILES['userfile']['size'] || $_FILES['userfile']['error']==2)
             return -1;
        //file name
        $userfile_t=$_FILES['userfile']['tmp_name'];
        //upload dir
        $dir="absolute/path/to/upload/dir";

        $dest=$dir . $userfile;

        //file correctly uploaded
        if(is_uploaded_file($userfile_t))
        {
                //we move it to upload dir
                if(!@move_uploaded_file($userfile_t,$dest))
                        return -3;
                //set perission
                @chmod($dest, 0664);
        }
        else
                return -3;

        //all right!
        return 1;
}


I think your problem is that your using $file as the filename.. ( i presume that this is what you call the input text box name on your form) and doing this is correct. you must reference the filename using $_REQUEST['file']['tmp_name'] to get the name of the file being uploaded.

Cheers,
0
 
LVL 13

Accepted Solution

by:
cLFlaVA earned 500 total points
ID: 12080988
Phil.........

First of all, change your code to this:
<?php

if($file_name != "") {
    copy ($file_name, "/usr/local/root/$file_name") or die("Could not Copy the File");
} else {
    die("No Files Specified");
}

?>

Second of all:
Where are you getting $file_name from?  It should be taken from the $_FILES global array.  Try this:

<?php
$file_name = $_FILES['file_field_name']['tmp_name'];
if($file_name != "") {
    copy ($file_name, "/usr/local/root/$file_name") or die("Could not Copy the File");
} else {
    die("No Files Specified");
}

?>
0
 
LVL 1

Author Comment

by:smphil
ID: 12081025

Cory
$file_name  is the name of the actual uploaded file
0
 
LVL 13

Expert Comment

by:cLFlaVA
ID: 12081032
Then try...

$file_name = $_FILES['file_name']['tmp_name'];
if($file_name != "") {
    copy ($file_name, "/usr/local/root/$file_name") or die("Could not Copy the File");
} else {
    die("No Files Specified");
}

And do make sure that your form has the property enctype="multipart/form-data"
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Both Easy and Powerful How easy is PHP? http://lmgtfy.com?q=how+easy+is+php (http://lmgtfy.com?q=how+easy+is+php)  Very easy.  It has been described as "a programming language even my grandmother can use." How powerful is PHP?  http://en.wikiped…
I imagine that there are some, like me, who require a way of getting currency exchange rates for implementation in web project from time to time, so I thought I would share a solution that I have developed for this purpose. It turns out that Yaho…
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…

895 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

13 Experts available now in Live!

Get 1:1 Help Now