I wonder whether someone may be able to help me please.
I've put together the following code which allows the user to select and manually upload files, saving it to a folder on my server which all works fine.
- <?php require_once "phpuploader/include_phpuploader.php" ?>
- <?php session_start(); ?>
- <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
- <html xmlns="http://www.w3.org/1999/xhtml">
- <head>
- <title>
- Form - Start uploading manually
- </title>
- <link href="demo.css" rel="stylesheet" type="text/css" />
-
- <script type="text/javascript">
- function doStart()
- {
- var uploadobj = document.getElementById('myuploader');
- if (uploadobj.getqueuecount() > 0)
- {
- uploadobj.startupload();
- }
- else
- {
- alert("Please browse files for upload");
- }
- }
- </script>
-
- </head>
- <body>
- <div class="demo">
- <h2>Start uploading manually</h2>
- <p>This sample demonstrates how to start uploading manually after file selection vs automatically.</p>
- <P>Allowed file types: <span style="color:red">jpg, gif, txt, png, zip</span></p>
-
- <!-- do not need enctype="multipart/form-data" -->
- <form id="form1" method="POST">
- <?php
- $uploader=new PhpUploader();
- $uploader->MaxSizeKB=10240;
- $uploader->Name="myuploader";
- $uploader->InsertText="Select multiple files (Max 10M)";
- $uploader->AllowedFileExtensions="*.jpg,*.png,*.gif,*.txt,*.zip,*.rar";
- $uploader->MultipleFilesUpload=true;
- $uploader->ManualStartUpload=true;
- $uploader->Render();
- ?>
- <br /><br /><br />
- <button id="submitbutton" onclick="doStart();return false;">Start Uploading Files</button>
-
-
- <br/><br/><br/>
- <?php
-
- $files=array();
-
- $processedlist=@$_POST["processedlist"];
- if($processedlist)
- {
- $guidlist=explode("/",$processedlist);
- foreach($guidlist as $fileguid)
- {
- $mvcfile=$uploader->GetUploadedFile($fileguid);
- if($mvcfile)
- {
- array_push($files,$mvcfile);
- }
- }
- }
- $fileguidlist=@$_POST["myuploader"];
- if($fileguidlist)
- {
- $guidlist=explode("/",$fileguidlist);
- foreach($guidlist as $fileguid)
- {
- $mvcfile=$uploader->GetUploadedFile($fileguid);
- if($mvcfile)
- {
-
-
-
- if($processedlist)
- $processedlist= $processedlist . "/" . $fileguid;
- else
- $processedlist= $fileguid;
-
- array_push($files,$mvcfile);
- }
- }
- }
-
- if(count($files)>0)
- {
- echo("<table style='border-collapse: collapse' class='Grid' border='0' cellspacing='0' cellpadding='2'>");
- foreach($files as $mvcfile)
- {
- echo("<tr>");
- echo("<td>");echo("<img src='phpuploader/resources/circle.png' border='0' />");echo("</td>");
- echo("<td>");echo($mvcfile->FileName);echo("</td>");
-
- echo("</tr>");
-
-
-
-
- $mvcfile->CopyTo("savefiles");
-
-
- }
- echo("</table>");
- }
-
- ?>
-
- <input type='hidden' name='processedlist' value='<?php echo($processedlist) ?>' />
-
- <br /><br />
- <input type='submit' value="Submit Form" />
-
- </form>
- </div>
- </body>
- </html>
What I'd now like to do is pass the filename variable to a mySql database. I've read the various posts on this forum and realised, or so I thought that the variable I need to capture is '$mvcfile'.
In the final verison of my form there will be a number of form fields besides the 'filename' variable I need to capture so I've put together the following php script to save the data.
- <?php
-
- require("phpfile.php");
-
-
-
- $conn = mysql_connect("hostname", $username, $password);
- if (!$conn)
- {
- die('Not connected : '.mysql_error());
- }
-
-
- $db_selected = mysql_select_db($database, $conn);
- if (!$db_selected)
- {
- die('Can\'t use db : '.mysql_error());
- }
-
- $query = "INSERT INTO testimages(imagename) VALUES ('$mvcfile')";
- $result = mysql_query($query, $conn);
-
- if (!$result)
- {
- die('Invalid query: '.mysql_error());
- }
-
- ?>
The problem is, is that I can't get this to pull the data from the variable and into my database. I've tried all different naming conventions without any luck. I just wondered whether someone could perhaps have a look at this please and let me know where I'm going wrong, or whether, indeed there's a simpler within the 'PHPFileUploader' software that allows you to do this.
Many thanks and regards
Chris