Uploading images

Posted on 2004-09-16
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.

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>
            <li>Sent: <?php echo "$file_name"; ?>
            <li>Size: <?php echo "$file_size"; ?>
            <li>Type: <?php echo "$file_type"; ?>
            <a href="<?php echo "$file_name" ?> ">
                                         Click Here to View File</a>
Question by:smphil
  • 2

Expert Comment

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
        //upload dir

        $dest=$dir . $userfile;

        //file correctly uploaded
                //we move it to upload dir
                        return -3;
                //set perission
                @chmod($dest, 0664);
                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.

LVL 13

Accepted Solution

cLFlaVA earned 500 total points
ID: 12080988

First of all, change your code to this:

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:

$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");


Author Comment

ID: 12081025

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

Expert Comment

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"

Featured Post

Microsoft Certification Exam 74-409

Veeam® is happy to provide the Microsoft community with a study guide prepared by MVP and MCT, Orin Thomas. This guide will take you through each of the exam objectives, helping you to prepare for and pass the examination.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
php construct 5 27
applying error reporting code to see paypal error messages 13 57
comma true 6 33
How to submit record from external php form to a Sharepoint list? 5 33
Popularity Can Be Measured Sometimes we deal with questions of popularity, and we need a way to collect opinions from our clients.  This article shows a simple teaching example of how we might elect a favorite color by letting our clients vote for …
3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
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…

777 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