I am working with a portal, where there is content type. The front end developer who made this portal added a CCK field for file attachment & there is already File attachment field given by core.
Now we won’t go to discuss why did he do that as I also don’t know.
Now I have to removed that CCK field & if I remove directly, I will loose all the data uploaded by this field as it will remove the table of it.
So now I am trying to replace the value from this CCK field table to default upload table & update the filepath in files table..so that it would come in view for attached files.
Because I am not very good at PHP or MySQL I am seeking some help from you guys..
Here is the basic code, which I have written…please suggest the correction & please tell me will I be able to connect remote server DB in doing it so –
<?php
mysql_connect("http://edlabs.in/connect:22","connect","");
mysql_select_db("connect");
for($i=0; $i<=1; $i++){
$fid_cck = array(mysql_query("SELECT field_upload_doc_fid FROM content_field_upload_doc WHERE field_upload_doc_list > 0"));
$fid_core = array(mysql_query("SELECT fid FROM upload"));
foreach($fid_cck as $fid_cck_value){
foreach($fid_core as $fid_core_value)
{
if($fid_cck_value != $fid_core_value){
$file_name = mysql_query("SELECT filename FROM files WHERE fid = $fid_cck");
$nid_cck = mysql_query("SELECT nid FROM field_upload_doc_fid WHERE fid = $fid_cck");
$vid_cck = mysql_query("SELECT vid FROM field_upload_doc_fid WHERE fid = $fid_cck");
mysql_query("INSERT INTO upload VALUES('$fid_cck', '$nid_cck', '$vid_cck', '$file_name', 1, 0)");
$filepath = array(mysql_query("SELECT filepath FROM files WHERE fid = $fid_cck"));
$new_filepath = str_replace("/background_docs", "", $filepath);
mysql_query("UPDATE files SET filepath=$new_filepath WHERE fid = $fid_cck");
}
}
}
}
?>
I have solved this problem by following these steps-
Removed the CCK field from content type…and it’s DONE..!
die('Could not connect: ' . mysql_error());
}
else{
}
?>