• Howdy! Welcome to our community of more than 130.000 members devoted to web hosting. This is a great place to get special offers from web hosts and post your own requests or ads. To start posting sign up here. Cheers! /Peo, FreeWebSpace.net
managed wordpress hosting

renaming files

If you want rename an existing file : rename("filename", "newname.txt") ;
If you want rename uploaded file (from /tmp) :
move_uploaded_file($HTTP_POST_FILES['myfile']['tmp_name'], $HTTP_POST_FILES['myfile']['name']) ;
And myfile is the name of your <input type=file> :<input name=myfile type=file> .
 
I'm not very good att coding and am learning as I go :)

below is my code (im not sure which of the suggestions is best.
I need to call the value from the id field (a number) add 1 and rename the image (number).jpg corresponding witht the id

<?php require_once('Connections/fishinglincs.php'); ?>
<?php
$filerename=$row_Recordset1['id'];
$filerename=$filerename+1
?>
<?php
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "")
{
$theValue = (!get_magic_quotes_gpc()) ? addslashes($theValue) : $theValue;

switch ($theType) {
case "text":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "long":
case "int":
$theValue = ($theValue != "") ? intval($theValue) : "NULL";
break;
case "double":
$theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
break;
case "date":
$theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
break;
case "defined":
$theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
break;
}
return $theValue;
}

$editFormAction = $HTTP_SERVER_VARS['PHP_SELF'];
if (isset($HTTP_SERVER_VARS['QUERY_STRING'])) {
$editFormAction .= "?" . $HTTP_SERVER_VARS['QUERY_STRING'];
}

if ((isset($HTTP_POST_VARS["MM_insert"])) && ($HTTP_POST_VARS["MM_insert"] == "form1")) {
$insertSQL = sprintf("INSERT INTO fishing (name, county, details, species, bans, contact, directions, description) VALUES (%s, %s, %s, %s, %s, %s, %s, %s)",
GetSQLValueString($HTTP_POST_VARS['name'], "text"),
GetSQLValueString($HTTP_POST_VARS['county'], "text"),
GetSQLValueString($HTTP_POST_VARS['details'], "text"),
GetSQLValueString($HTTP_POST_VARS['species'], "text"),
GetSQLValueString($HTTP_POST_VARS['bans'], "text"),
GetSQLValueString($HTTP_POST_VARS['Tickets'], "text"),
GetSQLValueString($HTTP_POST_VARS['direcions'], "text"),
GetSQLValueString($HTTP_POST_VARS['description'], "text"));

mysql_select_db($database_fishinglincs, $fishinglincs);
$Result1 = mysql_query($insertSQL, $fishinglincs) or die(mysql_error());
}

mysql_select_db($database_fishinglincs, $fishinglincs);
$query_Recordset1 = "SELECT * FROM fishing";
$Recordset1 = mysql_query($query_Recordset1, $fishinglincs) or die(mysql_error());
$row_Recordset1 = mysql_fetch_assoc($Recordset1);
$totalRows_Recordset1 = mysql_num_rows($Recordset1);
?>
<html>
<head>
<title>Untitled Document</title>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
</head>

<body>


<FORM name="form1" ENCTYPE="multipart/form-data" ACTION="<?php echo $editFormAction; ?>" METHOD="POST">
<p> Name of Water : &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp; &nbsp;&nbsp;
<input type="text" name="name">
<br>
<br>
County: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<input name="county" type="text" id="county">
<br>
<br>
Short Description: &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;
<br>
<textarea name="description" cols="50" rows="5" id="description"></textarea>
<br>
<br>
Full Details (best bait etc.): <br>
<textarea name="details" cols="50" rows="5" id="details"></textarea>
<br>
<br>
Species:<br>
<textarea name="species" cols="50" rows="5" id="species"></textarea>
<br>
<br>
Bans: <br>
<textarea name="bans" cols="50" rows="5" id="bans"></textarea>
<br>
<br>
Tickets available:;<br>
<textarea name="Tickets" cols="50" rows="5" id="Tickets"></textarea>
<br>
<br>
Directions from nearest Town: <br>
<textarea name="direcions" cols="50" rows="5" id="direcions"></textarea>
<br>
<br>
<p>The file:
<input name="myfile" type="jpg">
<INPUT TYPE="submit" VALUE="Upload">
</p>
<input type="hidden" name="MM_insert" value="form1">


<?php

// Image file upload by Bloody
// http://www.bloodys.com/
// email: info@bloodys.com
// If you use this script, please put a link back to http://www.bloodys.com/

$path = "";
$max_size = 200000;

if (is_uploaded_file($userfile)) {

if ($userfile_size>$max_size) { echo "The file is too big<br>\n"; exit; }

if (($userfile_type=="image/gif") || ($userfile_type=="image/pjpeg")) {

if (file_exists($path . $userfile_name)) { echo "The file already exists<br>\n"; exit; }

$res = copy($userfile, $path . $userfile_name);
if (!$res) {
echo "upload failed!<br>\n"; exit; }
else
echo "upload sucessful<br>\n";

echo "File Name: $userfile_name<br>\n";
echo "File Size: $userfile_size bytes<br>\n";
echo "File Type: $userfile_type<br>\n";
} else { echo "Wrong file type<br>\n"; exit; }

}
?>
<?php
rename("$userfile_name", "$filerename");


?>
</FORM>
<?php
echo "conents of filerename: $filerename";
?>

</body>
</html>
<?php
mysql_free_result($Recordset1);
?>
hope u can help

regards andy:)
 
ok so I cant get the file renamed, (still no good at coding :) )

is there a way to get the name of the file being uploaded and store it in a database.

hope you can help :)

regards andy
 
Sorry your code is too long and need time to understand .
I dont know what do you exactly need, but this may help you:
change that $res = copy($userfile, $path . $userfile_name);
to $res = copy($userfile, $path . $filerename);
 
Last edited:
Back
Top