Jump to content

I am curious why my uploaded image is not going to the proper folder


karatekid36

Recommended Posts

This is the first time I have worked with uploading files through and html form with php.  I can not see why this is not working.  I used this form once and it worked and then I started adding some other things to the file and of course it does not want to move the file properly anymore. I just can not see why it is not working anymore.  If anyone spots something please let me know....

<?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
Share on other sites

I checked the permissions and they we not correct.  I have since changed them to the proper permissions, but still it is not moving the file properly.  I also changed it to an absolute link and they only produced an error.  If anyone else has any other suggestions please let me know. 

Link to comment
Share on other sites

May not help, but force the script to recognize that you mean "the current directory" by prepending "./" to the folder name:

 

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

 

Is it moving the file at all, or is it moving it to an incorrect location?

Link to comment
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.