PHP upload script og formstruktur
Hejsa, jeg er ved at klampe en upload funktion sammen til en webapp, men får disse her når jeg forsøger at uploade et billede:
Notice: Undefined index: temp_name in /var/www/vhosts/band.com/httpdocs/tryingcode.php on line 31
Notice: Undefined index: temp_name in /var/www/vhosts/band.com/httpdocs/tryingcode.php on line 35
There was an error uploading the file, please try again.
Scriptet:
ini_set('display_errors', ON);
error_reporting(E_ALL);
if (!isset($_POST['upload']))
{
echo "
Choose a file to upload:
";
}
else
{
//
// path to the folder where the file is going to be placed in the end.
//
$target_path = "music_files/media_files/";
/* We add the original filename to the end of our target path.
Result is "/music_files/media_files/"filename".extension" */
$target_path = $target_path . basename($_FILES['uploadedfile']['name']);
//
// We decide what the temporay location of the uploaded file is..."
//
$_FILES['uploadedfile']['temp_name'];
//
//We attempt moving the file from the temporary location to the final location.
//
if(move_uploaded_file($_FILES['uploadedfile']['temp_name'], $target_path))
{
die("The file ". basename($_FILES['uploadedfile']['name']). " has been uploaded.");
}
else
{
die("There was an error uploading the file, please try again.");
}
}
Og derudover: Hvordan indarbejder man en uploadform i en eksisterende form uden at konflikte med W3C's standarder?
Hejsa.
- Log in to post comments
Kommentarer1
Re: PHP upload script og formstruktur
Du laver bare en side med en form på og fortæller action="/var/www/vhosts/band.com/httpdocs/tryingcode.php"
Du kan så selv tilpasse det til w3c