croosman
Wed 25 October 2006, 11:41 pm GMT +0200
I am using your the easy upload php and I am trying to rename the file to var assigned in url querystring. The value will always be included from the referrer where I am using it.
When I set the var manually in the upload page, it works and carries into the class ( $my_upload->DealerID = 1234]; ) but as
soon as I try it with the stringqueried var, it does not.
Here is the area that I modified for the new DB upload php.
---------------------------------------------------------------------------------------
<?php
include ($_SERVER['DOCUMENT_ROOT']."/classes/upload/upload_class.php"); //classes is the map where the class file is stored (one above the root)
$max_size = 1024*250; // the max. size for uploading
$my_upload = new file_upload;
$my_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/files/new/"; // "files" is the folder for the uploaded files (you have to create this folder)
$my_upload->extensions = array(".png", ".zip", ".pdf", ".jpg"); // specify the allowed extensions here
// $my_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
$my_upload->max_length_filename = 50; // change this value to fit your field length in your database (standard 100)
$my_upload->rename_file = true;
if (isset($_GET['DealerID']))
{
// The var is set, so lets process
// enter your code here
$my_upload->DealerID = $_GET['DealerID'];
// etc, etc
}
Here is the area from the class php that should rename the file to DealerID but it only names it to .jpg
As you can see, all I did was substitue DealerID for name in the rename function.
----------------------------------------------------------------------------------------------------------------------------------------------------
class file_upload {
var $DealerID;
var $the_file;
var $the_temp_file;
var $upload_dir;
var $replace;
var $do_filename_check;
var $max_length_filename = 100;
var $extensions;
var $ext_string;
var $language;
var $http_error;
var $rename_file; // if this var is true the file copy get a new name
var $file_copy; // the new name
var $message = array();
var $create_directory = true;
function file_upload() {
$this->language = "en"; // choice of en, nl, es
$this->rename_file = true;
$this->ext_string = "";
}
function show_error_string() {
$msg_string = "";
foreach ($this->message as $value) {
$msg_string .= $value."<br />\n";
}
return $msg_string;
}
function set_file_name($new_name = "") { // this "conversion" is used for unique/new filenames
if ($this->rename_file) {
if ($this->the_file == "") return;
$name = ($new_name == "") ? strtotime("now") : $new_name;
sleep(3);
$name = $this->DealerID.$this->get_extension($this->the_file);
} else {
$name = str_replace(" ", "_", $this->the_file); // space will result in problems on linux systems
}
return $name;
}
When I set the var manually in the upload page, it works and carries into the class ( $my_upload->DealerID = 1234]; ) but as
soon as I try it with the stringqueried var, it does not.
Here is the area that I modified for the new DB upload php.
---------------------------------------------------------------------------------------
<?php
include ($_SERVER['DOCUMENT_ROOT']."/classes/upload/upload_class.php"); //classes is the map where the class file is stored (one above the root)
$max_size = 1024*250; // the max. size for uploading
$my_upload = new file_upload;
$my_upload->upload_dir = $_SERVER['DOCUMENT_ROOT']."/files/new/"; // "files" is the folder for the uploaded files (you have to create this folder)
$my_upload->extensions = array(".png", ".zip", ".pdf", ".jpg"); // specify the allowed extensions here
// $my_upload->extensions = "de"; // use this to switch the messages into an other language (translate first!!!)
$my_upload->max_length_filename = 50; // change this value to fit your field length in your database (standard 100)
$my_upload->rename_file = true;
if (isset($_GET['DealerID']))
{
// The var is set, so lets process
// enter your code here
$my_upload->DealerID = $_GET['DealerID'];
// etc, etc
}
Here is the area from the class php that should rename the file to DealerID but it only names it to .jpg
As you can see, all I did was substitue DealerID for name in the rename function.
----------------------------------------------------------------------------------------------------------------------------------------------------
class file_upload {
var $DealerID;
var $the_file;
var $the_temp_file;
var $upload_dir;
var $replace;
var $do_filename_check;
var $max_length_filename = 100;
var $extensions;
var $ext_string;
var $language;
var $http_error;
var $rename_file; // if this var is true the file copy get a new name
var $file_copy; // the new name
var $message = array();
var $create_directory = true;
function file_upload() {
$this->language = "en"; // choice of en, nl, es
$this->rename_file = true;
$this->ext_string = "";
}
function show_error_string() {
$msg_string = "";
foreach ($this->message as $value) {
$msg_string .= $value."<br />\n";
}
return $msg_string;
}
function set_file_name($new_name = "") { // this "conversion" is used for unique/new filenames
if ($this->rename_file) {
if ($this->the_file == "") return;
$name = ($new_name == "") ? strtotime("now") : $new_name;
sleep(3);
$name = $this->DealerID.$this->get_extension($this->the_file);
} else {
$name = str_replace(" ", "_", $this->the_file); // space will result in problems on linux systems
}
return $name;
}