Soldato
- Joined
- 31 Oct 2005
- Posts
- 8,846
- Location
- Leeds
Hello again
Simple PHP help, currently have an uploading script that when left as it is, gathers the file from the form, and uploads it to my webserver in the defined folder, Nice.
Now I want to have control over the name of the file upload, as currently the filename is whatever the filename is on the uploaders pc
Anyhoo I have a session variable that I wish to use to name the image
Note ['uploaded'] is the field name from the form
Code looks like this
Nice and simple, now if I try renaming the [name] to ['$color'] (my session variable) I get an error on line 60 due to it looking for the tmp_name
Hopefully someone can point out where and how to put that session variable in so that when the file is upload it is named using the variable
Does that make sense?
Simple PHP help, currently have an uploading script that when left as it is, gathers the file from the form, and uploads it to my webserver in the defined folder, Nice.
Now I want to have control over the name of the file upload, as currently the filename is whatever the filename is on the uploaders pc
Anyhoo I have a session variable that I wish to use to name the image
Note ['uploaded'] is the field name from the form
Code looks like this
PHP:
<?php
session_start();
$color = $_SESSION['user_id'];
$target = "upload/";
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
//This is our size condition
if ($uploaded_size > 350000)
{
echo "Your file is too large.<br>";
$ok=0;
}
//This is our limit file type condition
if ($uploaded_type =="text/php")
{
echo "No PHP files<br>";
$ok=0;
}
//Here we check that $ok was not set to 0 by an error
if ($ok==0)
{
Echo "Sorry your file was not uploaded";
}
//If everything is ok we try to upload it
else
{
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploadedfile']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}
?>
Nice and simple, now if I try renaming the [name] to ['$color'] (my session variable) I get an error on line 60 due to it looking for the tmp_name
PHP:
if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
Hopefully someone can point out where and how to put that session variable in so that when the file is upload it is named using the variable
Does that make sense?