Several years ago we moved our web server from a shared server to a virtual private server, mainly so that we could install a better search engine that we couldn't install on the shared server. The move went fine and the search engine works like a charm. Unfortunately I'm still dealing with a few issues leftover from the move and I could use a little advise. Just FYI, my background is mainly as a Delphi / C developer and I'm the only computer technician left after layoffs and furloughs.
The problem is that there are a number of content management pages used to add / edit / delete data from the MySql database. The pages still work but several of them have an option to upload images to the website i.e. the board of directors editor includes an option to upload a photo and that photo is displayed on the directors page. What happens is that any edits or a new record updates just fine but the upload of the image fails. I found a good tutorial for PHP uploads here: W3Schools PHP Upload and I've been following it trying to see where there could be a problem and after several days and numerous hours I haven't spotted the problem but the example is coded somewhat differently than the upload script on the site.
I've tried adding some echo statements to try and see what the error message is but another problem is that when I hit the "Submit" button on the edit form the page clears and returns to the content management window and I'm never able to see the actual error message. I'm sorry to say that I'm probably spoiled from years of using an IDE with an integrated debugger so any debugging tips would be appreciated.
I'm going to include the code of the upload script that is being used below, I'd appreciate any help to try and resolve this issue.
Thanks,
- Chris
In the edit form this is the form statement:
The problem is that there are a number of content management pages used to add / edit / delete data from the MySql database. The pages still work but several of them have an option to upload images to the website i.e. the board of directors editor includes an option to upload a photo and that photo is displayed on the directors page. What happens is that any edits or a new record updates just fine but the upload of the image fails. I found a good tutorial for PHP uploads here: W3Schools PHP Upload and I've been following it trying to see where there could be a problem and after several days and numerous hours I haven't spotted the problem but the example is coded somewhat differently than the upload script on the site.
I've tried adding some echo statements to try and see what the error message is but another problem is that when I hit the "Submit" button on the edit form the page clears and returns to the content management window and I'm never able to see the actual error message. I'm sorry to say that I'm probably spoiled from years of using an IDE with an integrated debugger so any debugging tips would be appreciated.
I'm going to include the code of the upload script that is being used below, I'd appreciate any help to try and resolve this issue.
Thanks,
- Chris
In the edit form this is the form statement:
PHP:
<form action="index.html" method="post" enctype="multipart/form-data" >
<input type="hidden" name="table" value="<? echo "njhs_".$tablename ?>">
<input type="hidden" name="recid" value="<? echo $_GET["recid"] ?>">
<input type="hidden" name="action" value="updatedb">
<input type="hidden" name=assetPath value = "../assets">
PHP:
function upload($key){
$table = $_POST["table"];
$assetPath = $_POST["assetPath"];
$timestamp = $_POST["timestamp"];
$ulPath = "$assetPath/$table/$key";
$extension = substr($_FILES['upfile']['name'][$key], -3); // grabs the extension from the original file
$extension = strtolower($extension);
$orig_filename = $_FILES['upfile']['name'][$key];
echo "<p>Orig Name: ".$orig_filename."</p>";
$tmp_name = $_FILES['upfile']['tmp_name'][$key];
if ($extension == "gif" || $extension == "jpg") {
$new_name = "$timestamp.$extension";
} else {
$new_name = $orig_filename;
}
$the_file = "$ulPath/$new_name";
#echo "\$the_file = $the_file<br>\n";
if ($error) {
echo ($error);
return("FAILED upload");
} else { # cool, we can continue
if (!@copy($tmp_name, $the_file)) {
echo("\n<b>FAILED copying temp file. ($tmp_name to $the_file)</b><br>");
return("FAILED copy");
}
return $new_name;
}
}