This topic is locked
[SOLVED]

 Renaming Picture files and Thumbs

9/12/2016 10:12:07 PM
PHPRunner General questions
L
laserray author

I first started storing picture files, and such into blobs in the database. Reading the pros, and cons of doing such a thing. I tried to store my data files into folders which the database pointed to. I followed the help examples. I did have trouble with file permissions, but have seem to corrected them.

I want to take a file in, and rename the file, and/or the thumbnail, as well as the usrName.

I can get pdf's to upload, rename, store into the database correctly, for later web retrieval. The code to do the same thing refuses to work. The file is rename but the database field won't fill. I tracked it down to my_json_encode not working. (At least I think I have.
Here is the working code, loading pdf forms, and renaming them.

============================================================================================================

// get information about uploaded files

if ($values['W9Form']<> $oldvalues['W9Form']);

{

$fileArray = my_json_decode($values['W9Form']);

// rename files make sure your file permissions are set correctly

for($i = 0; $i < count($fileArray); $i++)

{

$fileName = $fileArray[$i]["name"];

$usrFileName = $fileArray[$i]["usrName"];

// new file names for user, file, thumb

$newFileName = "userfiles/w9/W9Form".$values["BusinessName"]."_".$i.date("m_d_Y").".pdf";

$newUsrFileName = "W9Form".$values["BusinessName"]."_".$i.date("m_d_Y").".pdf";

// rename files

rename($fileName, getabspath($newFileName));

chmod($newFileName, 0766);

// store New file names into array with correct JSON format

$fileArray[$i]["name"] = $newFileName;

$fileArray[$i]["usrName"] = $newUsrFileName;

}

// update values of the fields that stores file names

$values['W9Form'] = my_json_encode($fileArray);

}

if ($values['TaxResale']<> $oldvalues['TaxResale']);

{

$fileArray = my_jsondecode($values['TaxResale']);

// rename files

for($i = 0; $i < count($fileArray); $i++)

{

$fileName = $fileArray[$i]["name"];

$usrFileName = $fileArray[$i]["usrName"];

// new file names for user, file, thumb

$newFileName = "userfiles/tax/SalesTax
".$values["BusinessName"]."_".$i.date("m_dY").".pdf";

$newUsrFileName = "SalesTax
".$values["BusinessName"]."_".$i.date("m_d_Y").".pdf";

// rename files

rename($fileName, getabspath($newFileName));

chmod($newFileName, 0766);

// store New file names into array with correct JSON format

$fileArray[$i]["name"] = $newFileName;

$fileArray[$i]["usrName"] = $newUsrFileName;

}

// update values of the fields that stores file names

$values['TaxResale'] = my_json_encode($fileArray);

}
return true;
==================================================================================================
This code should be the same, but it uploads .jpg's, renames them, but won't store the data into the field that points to the folder.
===================================================================================================
if ($values['Picture1']<> $oldvalues['Picture1']);

{

$fileArray = my_jsondecode($values['Picture1']);

// rename files

for($i = 0; $i < count($fileArray); $i++)

{

$fileName = $fileArray[$i]["name"];

$thumbName = $fileArray[$i]["thumbnail"];

$usrFileName = $fileArray[$i]["usrName"];

// new file names for user, file, thumb

$newFileName = "userfiles/pictures1/PN".$values["PartNo"]."
".$i."_1.jpg";

$newUsrFileName = "PN".$values["PartNo"].$i."1.jpg";

$newThumbName = "userfiles/pictures1/PN".$values["PartNo"]."
".$i."_1_tbn.jpg";

// rename files

rename($fileName, getabspath($newFileName));

rename($thumbName, getabspath($newThumbName));

chmod($newFileName, 0766);

chmod($newThumbName, 0766);

// store New file names into array with correct JSON format

$fileArray[$i]["name"] = $newFileName;

$fileArray[$i]["usrName"] = $newUsrFileName;

$fileArray[$i]["thumbnail"] = $newThumbName;

}

// update values of the fields that stores file names

$values['Picture1'] = my_json_encode($fileArray);

}

return true;
===========================================================================================================
Why did I miss?
Thanks,

L
laserray author 9/13/2016



Check my post here:

http://www.asprunner.com/forums/topic/22846-read-image-exif-and-save-exif-value-to-database/


Appreciate the response. I reviewed many posts. Yours is the same as the others, but you add EXIF data. I don't need that.

I do have two extra data fields to be filled, usrName, and thunbnails. It seems when I add thumbnails to the code the my_json_encode breaks.

I read similar problems by another user with no solution. Either I made a simple coding mistake, or more is going on than I understand.

If I fill "Picture1" field data with the correct values, the pictures will display correctly. The problem is the code above will NOT store the encoded data.

Yet the same code works for pdf's.

Confused.....

lefty 9/13/2016



Appreciate the response. I reviewed many posts. Yours is the same as the others, but you add EXIF data. I don't need that.

I do have two extra data fields to be filled, usrName, and thunbnails. It seems when I add thumbnails to the code the my_json_encode breaks.

I read similar problems by another user with no solution. Either I made a simple coding mistake, or more is going on than I understand.

If I fill "Picture1" field data with the correct values, the pictures will display correctly. The problem is the code above will NOT store the encoded data.

Yet the same code works for pdf's.

Confused.....



Have you tried this without the pdf part . Just test with thumbnails and pics to see if it works . I would split theese into three different encode/decodes in the same event. I also don't see where the if ($values['W9Form']<> $oldvalues['W9Form']); ends ( you returned true ) without ending pdf's. also are the extensions for photos ending with jpeg or jpg. since you hardcoded jpg. And lastly are you using absolute path. ? If userfiles is outside your root you need to use the absolut path to your server folder. like C:\\Inetpub\\vhosts\\yourwebsite\\userfiles/pictures1/PN".$values["PartNo"]."_".$i."_1.jpg"; using absolute path worked better for me plus better security. And lastly if it is not saving to database , what database are you using .for example, Memo in MS Access, Mediumtext in MySQL, TEXT or Varchar(max) in SQL Server. You also need GD library installed on server for thumbnails. hope one of these options help. I tried blob fields in the past and have had issues with the above code you supplied.

L
laserray author 9/13/2016



Have you tried this without the pdf part . Just test with thumbnails and pics to see if it works . I would split theese into three different encode/decodes in the same event. I also don't see where the if ($values['W9Form']<> $oldvalues['W9Form']); ends ( you returned true ) without ending pdf's. also are the extensions for photos ending with jpeg or jpg. since you hardcoded jpg. And lastly are you using absolute path. ? If userfiles is outside your root you need to use the absolut path to your server folder. like C:\\Inetpub\\vhosts\\yourwebsite\\userfiles/pictures1/PN".$values["PartNo"]."_".$i."_1.jpg"; using absolute path worked better for me plus better security. And lastly if it is not saving to database , what database are you using .for example, Memo in MS Access, Mediumtext in MySQL, TEXT or Varchar(max) in SQL Server. You also need GD library installed on server for thumbnails. hope one of these options help. I tried blob fields in the past and have had issues with the above code you supplied.


Thank you for the suggestions. Every still point to the my_json_encode failure.

The "pdf" code works perfectly. I check my code, and W9 statement ends with a '}', maybe I drop it here? It passes the code check.

I've drop the thumbnails, no help. I tried without jpg extension. I am using mysql and the fields are varchar 400.

However the routines are two different databases, 'Customer List', which works with pdf, and "Parts Lists' which doesn't at all.

Using blobs would be simple, but it's bloating the database. I stopped before I went past no return.

This is driving me nuts, but you have given me, other ideas to try.
Thanks, I'll keep banging at it.

L
laserray author 9/13/2016

OK, after the above suggestions. I found....

That posted routine in the help files will NOT work on "jpg"

If you check the field data out, you see type "jpeg". Not sure if that reason.

Also, maybe I need to update "searchStr as well?

Really after all these years, nobody stores pictures in a folder? Nobody wanted to rename them? That can't be.

Even the examples, shopping cart, use blobs.
Here's some field data.
[{"name":"userfiles\/pictures1\/image_ektiagww.jpg","usrName":"image.jpg","size":44731,"type":"image\/jpeg","thumbnail":"userfiles\/pictures1\/Picture1DBimage_eoaaslob.jpg","thumbnail_type":"image\/jpeg","thumbnail_size":1064,"searchStr":"image.jpg,!:sStrEnd"}]
[{"name":"userfiles\/pictures1\/image_kwarfms2.jpg","usrName":"image.jpg","size":1492550,"type":"image\/jpeg","searchStr":"image.jpg,!:sStrEnd"}]
One that was correctly outputted;
[{"name":"userfiles\/w9\/W9Form _009_13_2016.pdf","usrName":"W9Form _009_13_2016.pdf","size":5385,"type":"binary\/octet-stream","searchStr":"W9Form _009_13_2016.pdf,!:sStrEnd"}]
my_json_encode is returning a [] null.

Am I going have to rebuild the field myself? <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=80299&image=1&table=forumreplies' class='bbc_emoticon' alt=':(' />
Thanks again, at least I'm heading in the right direction.

L
laserray author 9/14/2016

Thanks, I got it.
Place the code in the wrong event. The field was being written over.

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=80301&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=80301&image=2&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />
romaldus,
kept reading your post over, and over.
John,
Thanks
Learned a little bit more.

romaldus 9/14/2016



Thanks, I got it.
Place the code in the wrong event. The field was being written over.

<img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=80302&image=1&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' /> <img src='https://asprunner.com/forums/file.php?topicimage=1&fieldname=reply&id=80302&image=2&table=forumreplies' class='bbc_emoticon' alt=':rolleyes:' />
romaldus,
kept reading your post over, and over.
John,
Thanks
Learned a little bit more.


you are welcome