Jump to content

I don't see what's wrong with this uploading of a file...


Crash2108

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

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.