Jump to content

modfying file name using Pure PHP Upload


blurb87

Recommended Posts

I've put up a quick site to collect some basic biographical info and a head shot from a group of people for a project I'm working on.

 

I used the Pure PHP Upload/Sephiroth extension I found on Abobe's site for the file upload.

 

Once the biographical info is submitted, the next page is the one with the file upload form.  What I'd like to do is add the first name and last name (from the form) to the file name that is uploaded.  The reason I want to do this is that while I will probably know and be able to identify which pictures go with which person (the group of people I'm gathering info from is only about 75 people) if two people upload a picture called "pic" or "headshot" the first one will be overwritten. 

 

So, before the script copies the file to a specified folder, I want to add the name info from the form to the file name.

 

My only background in scripting is ASP/VB Script, so PHP is not my area although I'm trying to learn.

 

If anyone is from an ASP background, I feel like I should just be able to do a response.write with the form variable somewhere in the code and concatenate it with which ever variable the script uses to name the file.

 

I'm not trying to put the file location into my database or anything like that. 

 

My code is below, can anyone advise me on how to accomplish this?

 

<?php
//	---------------------------------------------
//	Pure PHP Upload version 1.1
//	-------------------------------------------
if (phpversion() > "4.0.6") {
$HTTP_POST_FILES = &$_FILES;
}
define("MAX_SIZE",3145728);
define("DESTINATION_FOLDER", "uploadBlue");
define("no_error", "ok.php");
define("yes_error", "error.php");
$_accepted_extensions_ = "jpg,gif";
if(strlen($_accepted_extensions_) > 0){
$_accepted_extensions_ = @explode(",",$_accepted_extensions_);
} else {
$_accepted_extensions_ = array();
}
$_file_ = $HTTP_POST_FILES['file'];
if(is_uploaded_file($_file_['tmp_name']) && $HTTP_POST_FILES['file']['error'] == 0){
$errStr = "";
$_name_ = $_file_['name'];
$_type_ = $_file_['type'];
$_tmp_name_ = $_file_['tmp_name'];
$_size_ = $_file_['size'];
if($_size_ > MAX_SIZE && MAX_SIZE > 0){
	$errStr = "File troppo pesante";
}
$_ext_ = explode(".", $_name_);
$_ext_ = strtolower($_ext_[count($_ext_)-1]);
if(!in_array($_ext_, $_accepted_extensions_) && count($_accepted_extensions_) > 0){
	$errStr = "Estensione non valida";
}
if(!is_dir(DESTINATION_FOLDER) && is_writeable(DESTINATION_FOLDER)){
	$errStr = "Cartella di destinazione non valida";
}
if(empty($errStr)){
	if(@copy($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_)){
		header("Location: " . no_error);
	} else {
		header("Location: " . yes_error);
	}
} else {
	header("Location: " . yes_error);
}
}
?>
[code]

[/code]

Link to comment
Share on other sites

This line....

 

if(@copy($_tmp_name_,DESTINATION_FOLDER . "/" . $_name_)){

 

Would need to be....

 

if(@copy($_tmp_name_,DESTINATION_FOLDER . "/" . $_POST['firstname'] . $_POST['lastname'] . $_name_)) {

 

Where firstname & lastname are the names of your form elements.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

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