Jump to content

Recommended Posts

In the following code, I can get everything to work except the actual movement of the image to the folder on my server.  This was working before I added some new code to the page, but now it seems to not want to add the file to the folder on my server.  When I submit the form, it tells me that everything is okay, but when I go and look on the server to see if the file is there and it is not!  Any help would be great. 

 

<?php

session_name ('YourVisitID');
session_start(); // Start the session.

// If no session value is present, redirect the user.
if (!isset($_SESSION['user_id'])) {

// Start defining the URL.
$url = 'http://' . $_SERVER['HTTP_HOST'] . dirname($_SERVER['PHP_SELF']);
// Check for a trailing slash.
if ((substr($url, -1) == '/') OR (substr($url, -1) == '\\') ) {
	$url = substr ($url, 0, -1); // Chop off the slash.
}
$url .= '/index.php'; // Add the page.
header("Location: $url");
exit(); // Quit the script.
}

$page_title = 'Upload Awards or Paddles';
include('./includes/header.html');

$counter = 1;

if(isset($_POST['submitted'])) {

require_once('./includes/mysql_connect.php');


for($i = 0; $i < $counter; $i++) {

$filename = 'upload' . $i;
$description = 'description' . $i;
$pledge_class = 'pledge_class';

if(isset($_FILES[$filename]) && ($_FILES[$filename]['error'] !=4)) {

	if(!empty($_POST[$description])) {
		$d = "'" . escape_data($_POST[$description]) . "'";

		} else {

		$d = 'NULL';

		}

	$query = "INSERT INTO ap_uploads (pledge_class, file_name, file_size, file_type, description) VALUES (pledge_class, '{$_FILES[$filename]['name']}', '{$_FILES[$filename]['size']}', '{$_FILES[$filename]['type']}', $d)";
	$result = mysql_query ($query);

if($result) {

$upload_id = mysql_insert_id();

if(move_uploaded_file($_FILES[$filename]['tmp_name'], "awards_paddles_img/$upload_id")) {

		echo '<p>File number ' . ($i + 1) . ' has been uploaded!</p>';

		} else {

		echo '<p><font color="red">File number ' . ($i +1) . 'could not be moved.</font></p>';

		$query = "DELETE FROM ap_uploads WHERE upload_id = $upload_id";
		$result = mysql_query($query);

		}

	} else {

		echo '<p><font color="red"> Your submission could not be processed due to a system error.</font></p>';

	}
}
}

mysql_close();

}
?>

<form enctype="multipart/form-data" action="upload_ap_images.php" method="post">

<fieldset><legend>Fill out the form to upload the image:</legend>
<input type="hidden" name="MAX_FILE_SIZE" value="524288" />

<br />

<p><b>Please Make Sure That There Are No Spaces In The File Name.</b></p>  <p>For Example, the filename picture 1.jpeg is not correct.  The filename picture1.jpeg or picture_1.jpeg is correct.</p>

<br />


<?php
for ($i = 0; $i < $counter; $i++) {

?><p>Pledge Class:<?php
  // Make the pledge class array.
$pledgeclass = array (1 => 'FF', 'Alpha', 'Beta', 'Gamma', 'Delta', 'Epsilon', 'Zeta', 'Eta', 'Theta', 'Iota', 'Kappa', 'Lambda', 'Mu', 'Nu', 'Xi', 'Omicron', 'Pi', 'Rho', 'Sigma', 'Tau', 'Upsilon', 'Phi', 'Chi', 'Psi', 'Omega');

// Make the pledge class pull-down menu.
echo '<select name="pledge_class">';

echo "<option value=\"\">Select Pledge Class</option>\n";
foreach ($pledgeclass as $key => $value) {

echo "<option value=\"$value\">$value</option>\n";
}
echo '</select>';
?></p><?php


echo ' <p><b>File:</b> <input type="file" name="upload' . $i . '" /></p>
       <p><b>Description:</b><br /> <textarea name="description' . $i . '" cols="40" rows="5"></textarea></p><br />
	   ';
	   }
	   
?>

</fieldset>
<input type="hidden" name="submitted" value="TRUE" />
<div align="center"><input type="submit" name="submit" value="Upload Images" /></div>

</form>

<?php
include ('./includes/footer.html');
?>

Link to comment
https://forums.phpfreaks.com/topic/51850-uploading-images-to-the-server/
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.