Page 1 of 1

Renaming Picture, or adding to the name.

Posted: Wed Jan 25, 2006 3:55 pm
by nickman013
I have a picture upload script.

The form:

Code: Select all

<form action=picture.php method=post>
<input type="file" name=uploadedfile>
<inpu type=submit>
</form>

The processor:

Code: Select all

$linktopic = $_FILES['uploadedfile']['name']; 
// Where the file is going to be placed 
$target_path = "/home/muot/public_html/pages/muotreport/submitted/";

/* Add the original filename to our target path. Result is "uploads/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 

// This is how we will get the temporary file...
$_FILES['uploadedfile']['tmp_name'];
$target_path = "/home/muot/public_html/pages/muotreport/submitted/";
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path))
{
echo "S";
} else{
echo "E";
}
I need to be able to add to the name or change the name of the picture. I know there is a way to change the name in that script, i just dont want to mess anything up.

Thanks!

Posted: Wed Jan 25, 2006 4:23 pm
by jayshields
I've added what you requested, cleaned it up and fixed some stuff.

The form:

Code: Select all

<form action="picture.php" method="post" enctype="multipart/form-data">
	<input type="file" name="uploadedfile" /><br />
	File name to use (w/ extension): <input type="text" name="newfilename" /><br />
	<input type="submit" name="submit" value="Submit" />
</form>
The processor:

Code: Select all

<?php

//Where the file is going to be placed
$uploaddir = "uploads/";

//Set the target for the file to be uploaded to
$target = $uploaddir . $_POST['newfilename'];

//Upload the file
if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target)) {
	echo 'File uploaded.';
} else {
	echo 'File upload error.';
}

?>
Obviously some sort of validation should be added to the processing script but I've just given you the basics.

Posted: Wed Jan 25, 2006 10:02 pm
by nickman013
Thanks alot, it is perfect!

I just got a Parse error, but i fixed it!

Thanks Again!

Posted: Thu Jan 26, 2006 4:25 am
by jayshields
No probs, but can I just ask which line the parse error was on? I can't see it in the code I gave you :?

Posted: Thu Jan 26, 2006 7:11 am
by nickman013
yes, it was this line

Code: Select all

} else {
I think you had one to many brackets, but I dont know lol.


Thanks Alot :D