Jump to content

Recommended Posts

This scrupt is to upload a file, and as far as I can tel, and all of the examples around uploading, there is nothing wrong with it.  But it doesn't work and can't move the file.

if(!$_POST==NULL || $_POST=='') {
$new_name = $_POST['name'].$_FILES['userfile']['name'];
  if ( $_FILES['userfile']['size'] > $MAX_SIZE) 
    {$message = "The file size is over 2MB.";}
else
{
$message = 'done';

    copy ($_FILES['userfile']['tmp_name'], $new_name) 
    or die ("Could not copy"); 
//move_uploaded_file($_FILES['userfile']['tmp_name'], $new_name);
mysql_query("INSERT INTO cart_products VALUES ('$_POST[name]', $_POST[price], '$_POST[desc]', '')");
}
}

as far as I know the name of the file you wish to copy it to, requires a file extension so copy knows what type of file to save it to such as

 

<?php
$file = 'example.txt';
$newfile = 'example2.txt'; //without the full filename and extension it wont copy

if (!copy($file, $newfile)) {
    echo "failed to copy $file...\n";
}
?> 

 

so you need to append a file extension to your $new_name such as .jpeg or some such whatever the file may be

I tried that, it didn't work.  I tried PHP.net's upload example, that didn't work.  I tried another upload script I had, and it finally gave me some information I could use.  It was simply another stupid error that wastes a couple hours of your life.

 

I forgot to give that directory permissions to change files...

 

I have to go back and backtrack all of the different codes I tried and try to get the best one working for my project and make up for lost time now...

I think this is something that causes you some error

 

 

//move_uploaded_file($_FILES['userfile']['tmp_name'], $new_name);

 

=====$new_name======

this variable should a location or a folder that the uploaded file should go

rest are still confuse me maybe you try this first and ask me if there's still error

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.