Jump to content

File Upload not working correctly


offsprg01

Recommended Posts

here's the code.

 

<? $FilePath = '../'; require ('../includes/header.inc'); ?>
<?php require_once('../Connections/TestDB.php'); ?>


<?php
if (!function_exists("GetSQLValueString")) {
function GetSQLValueString($theValue, $theType, $theDefinedValue = "", $theNotDefinedValue = "") 
{
  $theValue = get_magic_quotes_gpc() ? stripslashes($theValue) : $theValue;

  $theValue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($theValue) : mysql_escape_string($theValue);

  switch ($theType) {
    case "text":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;    
    case "long":
    case "int":
      $theValue = ($theValue != "") ? intval($theValue) : "NULL";
      break;
    case "double":
      $theValue = ($theValue != "") ? "'" . doubleval($theValue) . "'" : "NULL";
      break;
    case "date":
      $theValue = ($theValue != "") ? "'" . $theValue . "'" : "NULL";
      break;
    case "defined":
      $theValue = ($theValue != "") ? $theDefinedValue : $theNotDefinedValue;
      break;
  }
  return $theValue;
}
}

$editFormAction = $_SERVER['PHP_SELF'];
if (isset($_SERVER['QUERY_STRING'])) {
  $editFormAction .= "?" . htmlentities($_SERVER['QUERY_STRING']);
}


$uploadNotice = "No File Uploaded Yet";

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

// Where the file is going to be placed 
	$target_path = "uploads/";
	$filename = basename( $_FILES['uploadedfile']['name']); 
	$_FILES['uploadedfile']['tmp_name'];  
/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
	$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
	$_FILES['uploadedfile']['tmp_name']; 

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
    $uploadNotice = "The file ".  basename( $_FILES['uploadedfile']['name']). " has been uploaded.<br />";
} 
else{
    	$uploadNotice = "There was an error uploading the file, please try again!<br />";
}


  //now we save the file location and info in the database
  
  $insertSQL = sprintf("INSERT INTO PromoImages (FileName, StartDate, EndDate, `Default`, LeftRight) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($filename, "text"),
                       GetSQLValueString($_POST['StartDate'], "date"),
                       GetSQLValueString($_POST['EndDate'], "date"),
                       GetSQLValueString($_POST['Default'], "int"),
                       GetSQLValueString($_POST['LeftRight'], "int"));


  mysql_select_db($database_TestDB, $TestDB);
  $Result1 = mysql_query($insertSQL, $TestDB) or die(mysql_error());

  $insertGoTo = "ticker_create.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}
?>





  <div id="content">
    <? require ('../includes/exploreNav.inc'); ?>
    <div id="mainContent">
      <div align="left"><span class="contentHeader">UPLOAD A NEW TICKER</span></div>
      <br />
      <img src="../images/common/dottedLine.gif" alt="dottedline" width="480" height="6" /><br /><br />

	<p>Please fill out the information below.</p>
	<div class="mainContentHeading">Upload A New Ticker</div>
	<div class="mainContentBody" style="padding-top:5px; padding-bottom:5px; padding-right:30px; text-align:right">
			<form enctype="multipart/form-data" method="post" name="form1" action="<?php echo $editFormAction; ?>">
				<div style="float:right" align="left">
				  <input type="text" name="LeftRight" value="" size="32" />
				  <br />
				<input type="hidden" name="URL" value="" size="32">
				<input type="hidden" name="MAX_FILE_SIZE" value="100000" />
				<input name="uploadedfile" size="32" type="file" /><br />
				<?php
					if ($uploadNotice == "No File Uploaded Yet") {
						echo "File needs to be a .jpg or .gif (353 pixels wide and 65 pixels high)<br />";
					}
					else {
						echo $uploadNotice;
					}
				?>
				<input type="text" name="StartDate" value="<?php echo date('m-d-Y') ?>" size="32"><br />
				<input type="text" name="EndDate" value="<?php echo date('m-d-Y') ?>" size="32" /><br />
				<input type="text" name="Default" value="" size="32"><br />
				<input type="hidden" name="MM_insert" value="form1">
			  </div>
				<div style="line-height:17pt; padding-top:3px">
				Position Graphic: <br />
				Choose file to upload: <br /><div style="line-height:15pt"><br /></div>
				Start Date: <br />
				End Date: <br />
				Default Image: 
				</div>
				<br clear="all" />
				<input type="submit" style="background-color:#000066; color:#FFFFFF; border:none; font-size:10px; margin-top:5px" value="Upload File">
			</form>
	</div>

<p> </p>
      <img src="../images/common/dottedLine.gif" alt="dottedline" width="480" height="6" /><br />
<p> </p>
    
</div>     
<div id="contentOrangeBar"><img src="../images/common/inside_bar.gif" width="549" height="16" alt="inside bar" /></div>
  	<!--This forces all content to scale with the medium-->
	<div style="clear:both;"> </div>
</div>


<? require ('../includes/footer.inc'); ?>

 

here's the link please try and upload a file.

http://www.harwoodmarketinggroup.com/WIP/admin/promoImage_create.php

 

 

the file uploads to the temp arrays, but 'm guessing the break down is in the move_uploaded_file. the reason i say this is the file name goes in to the db correctly, but the file is not uploaded and an error is generated.

Link to comment
https://forums.phpfreaks.com/topic/40120-file-upload-not-working-correctly/
Share on other sites

i added your if statment, no error message, but still no file upload.

 

shouldn't the first if statment keep the script from executing until after the form is submited?

$uploadNotice = "No File Uploaded Yet";

if ((isset($_POST["MM_insert"])) && ($_POST["MM_insert"] == "form1")) {

// Where the file is going to be placed 
	$target_path = "/uploads/";
	$filename = basename( $_FILES['uploadedfile']['name']); 
	$_FILES['uploadedfile']['tmp_name'];  
/* Add the original filename to our target path.  
Result is "uploads/filename.extension" */
	$target_path = $target_path . basename( $_FILES['uploadedfile']['name']); 
	$_FILES['uploadedfile']['tmp_name']; 
if(is_uploaded_file($_FILES['uploadedfile']['tmp_name'])){
	if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
	    $uploadNotice = "The file ".  basename( $_FILES['uploadedfile']['name']). " has been uploaded.<br />";
	} 
	else{
    	$uploadNotice = "There was an error uploading the file, please try again!<br />";
	}
}

  //now we save the file location and info in the database
  
  $insertSQL = sprintf("INSERT INTO PromoImages (FileName, StartDate, EndDate, `Default`, LeftRight) VALUES (%s, %s, %s, %s, %s)",
                       GetSQLValueString($filename, "text"),
                       GetSQLValueString($_POST['StartDate'], "date"),
                       GetSQLValueString($_POST['EndDate'], "date"),
                       GetSQLValueString($_POST['Default'], "int"),
                       GetSQLValueString($_POST['LeftRight'], "int"));


  mysql_select_db($database_TestDB, $TestDB);
  $Result1 = mysql_query($insertSQL, $TestDB) or die(mysql_error());

  $insertGoTo = "ticker_create.php";
  if (isset($_SERVER['QUERY_STRING'])) {
    $insertGoTo .= (strpos($insertGoTo, '?')) ? "&" : "?";
    $insertGoTo .= $_SERVER['QUERY_STRING'];
  }
  header(sprintf("Location: %s", $insertGoTo));
}

Try this format

if(is_uploaded_file($_FILES['uploadedfile']['tmp_name']))

{

                $target_path = "/uploads/";

$filename = basename( $_FILES['uploadedfile']['name']);

                $target_path = $target_path .$filename;

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {

    $uploadNotice = "The file ".  basename( $_FILES['uploadedfile']['name']). " has been uploaded.<br />";

}

                else

{

echo "cannot move uploaded file";

}

 

}

else

{echo "cannot upload";

}

well i have not clue what fixed but after i tried your second suggestion and it did not work, my originaly code started working for no apparent reason. go figure. some times i think my compuer just likes to jack with me. especially when my deadline is 8am the next day.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.