CURDATE

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
michaelk46
Forum Commoner
Posts: 67
Joined: Mon Oct 12, 2009 9:50 pm

CURDATE

Post 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.
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: CURDATE

Post by AbraCadaver »

Code: Select all

$row1 = mysqli_fetch_array($result1);
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
Benwahballz
Forum Commoner
Posts: 25
Joined: Mon Sep 21, 2009 12:54 pm

Re: CURDATE

Post 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);
 
User avatar
AbraCadaver
DevNet Master
Posts: 2572
Joined: Mon Feb 24, 2003 10:12 am
Location: The Republic of Texas
Contact:

Re: CURDATE

Post 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.
mysql_function(): WARNING: This extension is deprecated as of PHP 5.5.0, and will be removed in the future. Instead, the MySQLi or PDO_MySQLextension should be used. See also MySQL: choosing an API guide and related FAQ for more information.
michaelk46
Forum Commoner
Posts: 67
Joined: Mon Oct 12, 2009 9:50 pm

Re: CURDATE

Post by michaelk46 »

I was completely unaware that PHP had a date function... Thank You very much for that...
Post Reply