Page 1 of 1

CURDATE

Posted: Wed Jan 13, 2010 2:24 pm
by michaelk46
pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.


Running into an issue trying to rename a file name by appending the name with the Current date while moving it to another location
I'm close, but not quite there....

Here is my code...

Code: Select all

$sql1='SELECT CURDATE();';
$result1 = mysqli_query($link, $sql1);
$row1[] = mysqli_fetch_array($result1);
$date = implode(',', $row1);
$destfile='C:/wamp/www/Test/Upload/Files/csv/' . basename($_FILES['upload']['name'] . $date);
$ret = move_uploaded_file($_FILES['upload']['tmp_name'], $destfile);


It actually makes two files in the appropriate folder
Book1.csv2010-01-13,2010-01-13
and
Book1.csvArray

and I get two messages when the code runs:

Notice: Array to string conversion in C:\wamp\www\Test\Upload\index.php on line 55
Warning: mysqli_query() [function.mysqli-query]: (00000/0): in C:\wamp\www\Test\Upload\index.php on line 72
query failed:

what am I doing wrong?

BTW... I know there is a problem with where the appended data is showing up, but I am not worried about that currently... I am only looking to get it to create one file with the date on the end of the file name once


pickle | Please use [ code=php ], [ code=text ], etc tags where appropriate when posting code. Your post has been edited to reflect how we'd like it posted. Please read: :arrow: Posting Code in the Forums to learn how to do it too.

Re: CURDATE

Posted: Wed Jan 13, 2010 2:31 pm
by AbraCadaver

Code: Select all

$row1 = mysqli_fetch_array($result1);

Re: CURDATE

Posted: Wed Jan 13, 2010 2:33 pm
by Benwahballz
Is there a specific reason that you are hitting the database just to get the date?

Why not use the date functions included in php? and append that to the file name?

http://ca2.php.net/manual/en/function.date.php

Also maybe try

Code: Select all

 
$destfile='C:/wamp/www/Test/Upload/Files/csv/' . basename($_FILES['upload']['name'],".csv") . $date . ".csv" ;
$ret = move_uploaded_file($_FILES['upload']['tmp_name'], $destfile);
 

Re: CURDATE

Posted: Wed Jan 13, 2010 2:34 pm
by AbraCadaver
But I would probably use this instead of all that:

Code: Select all

$date = date('Y-m-d');
EDIT: Doh, beat me to it.

Re: CURDATE

Posted: Wed Jan 13, 2010 2:37 pm
by michaelk46
I was completely unaware that PHP had a date function... Thank You very much for that...