envexlabs Posted June 27, 2007 Share Posted June 27, 2007 here is my upload function: function upload_image($upload_dir, $store_pic_id){ //sets the directory and name for the file $uploaddir = 'uploads/'. $upload_dir .'/'; $uploadfile = $uploaddir . basename($_FILES['userfile']['name']); if (move_uploaded_file($_FILES['userfile']['tmp_name'], $uploadfile)) { echo('<h2>Congratulations</h2>'); echo("Your file has been uploaded!<br /><br />"); echo('<img src="uploads/' . $upload_dir . '/'. $_FILES[userfile][name] . '" />'); echo('<br /><br /><a href="profile.php">Back to Profile</a>'); } else { echo "Possible file upload attack!\n"; } [color=blue]//puts the array into a variable so that it can be inputed into the database as a name.ext instead of Array[] $name = $_FILES[userfile][name];[/color] //updates the table with the new avatar image //$query = "UPDATE `t_info` SET `av` = '$name' WHERE ID = '$ID'"; //$result = mysql_query($query) or die(mysql_error()); //changes the permissions of the file chmod('uploads/'. $upload_dir .'/' . $name . '', 0644); } If i change the blue text to say, $name = 'test'; i get errors. I want to set the image name to a members ID number. how would i achieve this? Thanks, envex Quote Link to comment Share on other sites More sharing options...
papaface Posted June 27, 2007 Share Posted June 27, 2007 $_FILES['userfile']['name'] = "newname"; I presume that will work. Quote Link to comment Share on other sites More sharing options...
envexlabs Posted June 27, 2007 Author Share Posted June 27, 2007 no dice, i need to be able to keep the file extension, just change the name. Quote Link to comment Share on other sites More sharing options...
papaface Posted June 27, 2007 Share Posted June 27, 2007 The just explode the filename: $parts = explode(".",$_FILES['userfile']['name']); $_FILES['userfile']['name'] = "newname" . $parts[1]; That should work, but it isnt foolproof, as it relies on there just being 1 dot in the name. Quote Link to comment Share on other sites More sharing options...
envexlabs Posted June 27, 2007 Author Share Posted June 27, 2007 still getting errors :S Quote Link to comment Share on other sites More sharing options...
papaface Posted June 27, 2007 Share Posted June 27, 2007 Well explain yourself! What errors? Quote Link to comment Share on other sites More sharing options...
envexlabs Posted June 27, 2007 Author Share Posted June 27, 2007 hey, sorry, i forgot to input the error, trying to do 5 things at once Warning: chmod() [function.chmod]: No such file or directory in /mnt/gs02/herd02/20143/domains/werehavingasale.com/html/inc/php_functions.php on line 204 i'm going to play around, i dont think it's a name change error anymore. will update soon. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.