Jump to content

Upload Images Script To Certain Directory


Xtremer360

Recommended Posts

With this script it's supposed to when filled out post the information into the shows table with the showname,type,showimage. However with the showimage what I want it to do is when the admin clicks browse and finds the showimage he wants to assign to that show I want the image to be sent to the images folder in the main directory as well as I want it to take the file name like whatever.jpg and put that into the shows table as well under showimage. When I run the script right now it gives me the following error:

 

Parse error: parse error, unexpected $ in /home/content/y/a/n/yankeefaninkc/html/backstage/addshowname.php on line 63

 

 

What did I do wrong and for what I want the script to do did I write it all correctly.

 

<?php

 

/* addshowname.php */

 

/* This form after submission takes the results of the form and inserts the values into the database as a new show name is created. */

 

require ('database.php');

 

// Where the file is going to be placed

$target_path = "/home/content/y/a/n/yankeefaninkc/html/images/";

 

/* Add the original filename to our target path. 

Result is "images/filename.extension" */

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

 

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

    echo "The file ".  basename( $_FILES['uploadedfile']['name']).

    " has been uploaded";

} else{

    echo "There was an error uploading the file, please try again!";

}

 

//This code runs if the form has been submitted

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

 

//This makes sure they did not leave any fields blank

if (!$_POST['showname'] || !$_POST['type'] || !$_POST['showimage'] ) {

die('You did not complete all of the required fields');

}

 

// checks if the username is in use

if (!get_magic_quotes_gpc()) {

$_POST['showname'] = addslashes($_POST['showname']);

}

$showname = $_POST['showname'];

$check = mysql_query("SELECT showname FROM shows WHERE showname = '$showname'")

or die(mysql_error());

$check2 = mysql_num_rows($check);

 

//if the name exists it gives an error

if ($check2 != 0) {

die('Sorry, the show name '.$_POST['showname'].' is already in use.');

}

 

// now we insert it into the database

$insert = "INSERT INTO shows (showname, type, showimage)

VALUES ('".$_POST['showname']."','".$_POST['type']."','".$_POST['showimage']."')";

$add_show = mysql_query($insert,$link) or die(mysql_error());

 

echo '<form enctype="multipart/form-data" action="addshowname.php" method="post">';

echo '<input name="MAX_FILE_SIZE" type="hidden" value="30000">';

 

echo '<fieldset>';

echo '<legend>Enter the following information to add a show name:</legend>';

echo '<p><b>Enter Show Name:</b><input name="showname" type="text"></p>';

echo '<p><b>Show Type:</b><select name="type"><option></option><option>Weekly Show</option><option>Pay Per View</option></select></p>';

echo '<p><b>Upload Show Image:</b><input name="showimage" type="file"></p>';

echo '<div align="center"><input name="submit" type="submit"><input name="sumbitted" type="hidden" value="TRUE"></div>';

echo '</fieldset>';

 

echo '</form>';

 

?>

Link to comment
Share on other sites

you are missing a } at the end of the script

 

echo '<fieldset>';
echo '<legend>Enter the following information to add a show name:</legend>';
echo '<p>Enter Show Name:<input name="showname" type="text"></p>';
echo '<p>Show Type:<select name="type"><option></option><option>Weekly Show</option><option>Pay Per View</option></select></p>';
echo '<p>Upload Show Image:<input name="showimage" type="file"></p>';
echo '<div align="center"><input name="submit" type="submit"><input name="sumbitted" type="hidden" value="TRUE"></div>';
echo '</fieldset>';

echo '</form>';

}    ----------- THIS IS THE ONE YOU ARE MISSING!!

 

please use the code tags in this forum so we can see code properly

Link to comment
Share on other sites

<?php

/* addshowname.php */

/* This form after submission takes the results of the form and inserts the values into the database as a new show name is created. */

require ('database.php');

// Where the file is going to be placed
$target_path = "/home/content/y/a/n/yankeefaninkc/html/images/";

/* Add the original filename to our target path. 
Result is "images/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

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

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

}

//This code runs if the form has been submitted


//This makes sure they did not leave any fields blank
if (!$_POST['showname'] || !$_POST['type'] || !$_POST['showimage'] ) {
die('You did not complete all of the required fields');
}

// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['showname'] = addslashes($_POST['showname']);
}
$showname = $_POST['showname'];
$check = mysql_query("SELECT showname FROM shows WHERE showname = '$showname'")
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the show name '.$_POST['showname'].' is already in use.');
}

// now we insert it into the database
$insert = "INSERT INTO shows (showname, type, showimage)
VALUES ('".$_POST['showname']."','".$_POST['type']."','".$_POST['showimage']."')";
$add_show = mysql_query($insert,$link) or die(mysql_error());

echo '<form enctype="multipart/form-data" action="addshowname.php" method="post">';
echo '<input name="MAX_FILE_SIZE" type="hidden" value="30000">';

echo '<fieldset>';
echo '<legend>Enter the following information to add a show name:</legend>';
echo '<p>Enter Show Name:<input name="showname" type="text"></p>';
echo '<p>Show Type:<select name="type"><option></option><option>Weekly Show</option><option>Pay Per View</option></select></p>';
echo '<p>Upload Show Image:<input name="showimage" type="file"></p>';
echo '<div align="center"><input name="submit" type="submit"><input name="sumbitted" type="hidden" value="TRUE"></div>';
echo '</fieldset>';

echo '</form>';

?>

 

try that and tell me what happens....

Link to comment
Share on other sites

ok dont worry about the database stuff so much, just worry about the file upload.

 

 

<?php

/* addshowname.php */

/* This form after submission takes the results of the form and inserts the values into the database as a new show name is created. */

// Where the file is going to be placed
$target_path = "/home/content/y/a/n/yankeefaninkc/html/images/";

/* Add the original filename to our target path. 
Result is "images/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

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

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

}

echo '<form enctype="multipart/form-data" action="test.php" method="post">';
echo '<input name="MAX_FILE_SIZE" type="hidden" value="30000">';

echo '<fieldset>';
echo '<legend>Enter the following information to add a show name:</legend>';
echo '<p>Enter Show Name:<input name="showname" type="text"></p>';
echo '<p>Show Type:<select name="type"><option></option><option>Weekly Show</option><option>Pay Per View</option></select></p>';
echo '<p>Upload Show Image:<input name="showimage" type="file"></p>';
echo '<div align="center"><input name="submit" type="submit"><input name="sumbitted" type="hidden" value="TRUE"></div>';
echo '</fieldset>';

echo '</form>';

?>

Link to comment
Share on other sites

I can see what you have done wrong

 

you need to rename your <input name> to uploadedfile

 

so ur form looks like this

 

<form enctype="multipart/form-data" action="addshowname.php" method="post">
<input name="MAX_FILE_SIZE" type="hidden" value="100000">
<legend>Enter the following information to add a show name:</legend>
<p>Enter Show Name:<input name="showname" type="text"></p>
<p>Show Type:<select name="type"><option></option><option>Weekly Show</option><option>Pay Per View</option></select></p>
<p>Upload Show Image:<input name="uploadedfile" type="file"></p>
<div align="center"><input name="submit" type="submit"></div>
</form>

 

you are better off putting this outside of your php tags

Link to comment
Share on other sites

<?php

/* addshowname.php */

/* This form after submission takes the results of the form and inserts the values into the database as a new show name is created. */

//require ('database.php');

// Where the file is going to be placed
$target_path = "home/content/y/a/n/yankeefaninkc/html/images/";

/* Add the original filename to our target path. 
Result is "images/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

//This code runs if the form has been submitted
if (isset($_POST['submit'])) {

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



}

// checks if the username is in use
//if (!get_magic_quotes_gpc()) {
//$_POST['showname'] = addslashes($_POST['showname']);
//}
//$showname = $_POST['showname'];
//$check = mysql_query("SELECT showname FROM shows WHERE showname = '$showname'")
//or die(mysql_error());
//$check2 = mysql_num_rows($check);

//if the name exists it gives an error
//if ($check2 != 0) {
//die('Sorry, the show name '.$_POST['showname'].' is already in use.');
//}

// now we insert it into the database
//$insert = "INSERT INTO shows (showname, type, showimage)
//VALUES ('".$_POST['showname']."','".$_POST['type']."','".$_POST['showimage']."')";
//$add_show = mysql_query($insert,$link) or die(mysql_error());

echo '<form enctype="multipart/form-data" action="addshowname.php" method="post">';
echo '<input name="MAX_FILE_SIZE" type="hidden" value="100000">';
echo '<fieldset>';
echo '<legend>Enter the following information to add a show name:</legend>';
echo '<p>Enter Show Name:<input name="showname" type="text"></p>';
echo '<p>Show Type:<select name="type"><option></option><option>Weekly Show</option><option>Pay Per View</option></select></p>';
echo '<p>Upload Show Image:<input name="uploadedfile" type="file"></p>';
echo '<div align="center"><input name="submit" type="submit"><input name="sumbitted" type="hidden" value="TRUE"></div>';
echo '</fieldset>';
echo '</form>';



?>

 

i have tried this on a testing server so i know it works

 

try that and let me know how u get on..

 

try uploading something small first

 

Gaz

 

 

p.s. if it does not upload check the path you are supplying

Link to comment
Share on other sites

Parse error: parse error, unexpected '&' in /home/content/y/a/n/yankeefaninkc/html/backstage/addshowname.php on line 20

 

<?php

/* addshowname.php */

/* This form after submission takes the results of the form and inserts the values into the database as a new show name is created. */

require ('database.php');

// Where the file is going to be placed
$target_path = "home/content/y/a/n/yankeefaninkc/html/images/";

/* Add the original filename to our target path. 
Result is "images/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

//This code runs if the form has been submitted
if (isset($_POST['submit'])) {

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
&#160; &#160; echo "The file ".&#160; basename( $_FILES['uploadedfile']['name']).
&#160; &#160; " has been uploaded";
} else{
&#160; &#160; echo "There was an error uploading the file, please try again!";
}



}

checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['showname'] = addslashes($_POST['showname']);
}
$showname = $_POST['showname'];
$check = mysql_query("SELECT showname FROM shows WHERE showname = '$showname'")
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the show name '.$_POST['showname'].' is already in use.');
}

// now we insert it into the database
$insert = "INSERT INTO shows (showname, type, showimage)
VALUES ('".$_POST['showname']."','".$_POST['type']."','".$_POST['showimage']."')";
$add_show = mysql_query($insert,$link) or die(mysql_error());

echo '<form enctype="multipart/form-data" action="addshowname.php" method="post">';
echo '<input name="MAX_FILE_SIZE" type="hidden" value="100000">';
echo '<fieldset>';
echo '<legend>Enter the following information to add a show name:</legend>';
echo '<p>Enter Show Name:<input name="showname" type="text"></p>';
echo '<p>Show Type:<select name="type"><option></option><option>Weekly Show</option><option>Pay Per View</option></select></p>';
echo '<p>Upload Show Image:<input name="uploadedfile" type="file"></p>';
echo '<div align="center"><input name="submit" type="submit"><input name="sumbitted" type="hidden" value="TRUE"></div>';
echo '</fieldset>';
echo '</form>';



?>

Link to comment
Share on other sites

sometimes php freaks does this sometimes

 

&#160  ---= not sure why

 

<?php

/* addshowname.php */

/* This form after submission takes the results of the form and inserts the values into the database as a new show name is created. */

//require ('database.php');

// Where the file is going to be placed
$target_path = "home/content/y/a/n/yankeefaninkc/html/images/";

/* Add the original filename to our target path. 
Result is "images/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

//This code runs if the form has been submitted
if (isset($_POST['submit'])) {

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

}

// checks if the username is in use
//if (!get_magic_quotes_gpc()) {
//$_POST['showname'] = addslashes($_POST['showname']);
//}
//$showname = $_POST['showname'];
//$check = mysql_query("SELECT showname FROM shows WHERE showname = '$showname'")
//or die(mysql_error());
//$check2 = mysql_num_rows($check);

//if the name exists it gives an error
//if ($check2 != 0) {
//die('Sorry, the show name '.$_POST['showname'].' is already in use.');
//}

// now we insert it into the database
//$insert = "INSERT INTO shows (showname, type, showimage)
//VALUES ('".$_POST['showname']."','".$_POST['type']."','".$_POST['showimage']."')";
//$add_show = mysql_query($insert,$link) or die(mysql_error());

echo '<form enctype="multipart/form-data" action="addshowname.php" method="post">';
echo '<input name="MAX_FILE_SIZE" type="hidden" value="100000">';
echo '<fieldset>';
echo '<legend>Enter the following information to add a show name:</legend>';
echo '<p>Enter Show Name:<input name="showname" type="text"></p>';
echo '<p>Show Type:<select name="type"><option></option><option>Weekly Show</option><option>Pay Per View</option></select></p>';
echo '<p>Upload Show Image:<input name="uploadedfile" type="file"></p>';
echo '<div align="center"><input name="submit" type="submit"><input name="sumbitted" type="hidden" value="TRUE"></div>';
echo '</fieldset>';
echo '</form>';



?>

 

 

copy and paste that code....

Link to comment
Share on other sites

<?php

/* addshowname.php */

/* This form after submission takes the results of the form and inserts the values into the database as a new show name is created. */

require ('database.php');

// Where the file is going to be placed
$target_path = "home/content/y/a/n/yankeefaninkc/html/images/";

/* Add the original filename to our target path. 
Result is "images/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

//This code runs if the form has been submitted
if (isset($_POST['submit'])) {

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



// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['showname'] = addslashes($_POST['showname']);
}
$showname = $_POST['showname'];
$check = mysql_query("SELECT showname FROM shows WHERE showname = '$showname'")
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the show name '.$_POST['showname'].' is already in use.');
}

//now we insert it into the database
$insert = "INSERT INTO shows (showname, type, showimage)
VALUES ('".$_POST['showname']."','".$_POST['type']."','".$_POST['showimage']."')";
$add_show = mysql_query($insert,$link) or die(mysql_error());

}

echo '<form enctype="multipart/form-data" action="addshowname.php" method="post">';
echo '<input name="MAX_FILE_SIZE" type="hidden" value="100000">';
echo '<fieldset>';
echo '<legend>Enter the following information to add a show name:</legend>';
echo '<p>Enter Show Name:<input name="showname" type="text"></p>';
echo '<p>Show Type:<select name="type"><option></option><option>Weekly Show</option><option>Pay Per View</option></select></p>';
echo '<p>Upload Show Image:<input name="uploadedfile" type="file"></p>';
echo '<div align="center"><input name="submit" type="submit"><input name="sumbitted" type="hidden" value="TRUE"></div>';
echo '</fieldset>';
echo '</form>';



?>

 

ok ive got rid of the comments so the db should work

 

http://www.thedesignmonkeys.co.uk/portfolio/test.php

 

its there so i know it works

Link to comment
Share on other sites

Actually I tried it on mine and here's what came up:

 

Warning: move_uploaded_file(home/content/y/a/n/yankeefaninkc/html/images/aggression.jpg): failed to open stream: No such file or directory in /home/content/y/a/n/yankeefaninkc/html/backstage/addshowname.php on line 19

 

Warning: move_uploaded_file(): Unable to move '/tmp/phpwzy3jd' to 'home/content/y/a/n/yankeefaninkc/html/images/aggression.jpg' in /home/content/y/a/n/yankeefaninkc/html/backstage/addshowname.php on line 19

There was an error uploading the file, please try again!

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/y/a/n/yankeefaninkc/html/backstage/addshowname.php on line 44

Link to comment
Share on other sites

Same thing. However keep in mind that this is how my folders are setup right now.

 

images

folder1

folder 2

backstage

    addshowname.php

 

 

Warning: move_uploaded_file(/images/aggression.jpg): failed to open stream: No such file or directory in /home/content/y/a/n/yankeefaninkc/html/backstage/addshowname.php on line 19

 

Warning: move_uploaded_file(): Unable to move '/tmp/phpkn4sLD' to '/images/aggression.jpg' in /home/content/y/a/n/yankeefaninkc/html/backstage/addshowname.php on line 19

There was an error uploading the file, please try again!

Warning: mysql_query(): supplied argument is not a valid MySQL-Link resource in /home/content/y/a/n/yankeefaninkc/html/backstage/addshowname.php on line 44

Link to comment
Share on other sites

Same and this is frustrating for me and I'm sure it is for you:

 

<?php

/* addshowname.php */

/* This form after submission takes the results of the form and inserts the values into the database as a new show name is created. */

require ('database.php');

// Where the file is going to be placed
$target_path = "images/";

/* Add the original filename to our target path. 
Result is "images/filename.extension" */
$target_path = $target_path . basename( $_FILES['uploadedfile']['name']);

//This code runs if the form has been submitted
if (isset($_POST['submit'])) {

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



// checks if the username is in use
if (!get_magic_quotes_gpc()) {
$_POST['showname'] = addslashes($_POST['showname']);
}
$showname = $_POST['showname'];
$check = mysql_query("SELECT showname FROM shows WHERE showname = '$showname'")
or die(mysql_error());
$check2 = mysql_num_rows($check);

//if the name exists it gives an error
if ($check2 != 0) {
die('Sorry, the show name '.$_POST['showname'].' is already in use.');
}

//now we insert it into the database
$insert = "INSERT INTO shows (showname, type, showimage)
VALUES ('".$_POST['showname']."','".$_POST['type']."','".$_POST['showimage']."')";
$add_show = mysql_query($insert,$link) or die(mysql_error());

}

echo '<form enctype="multipart/form-data" action="addshowname.php" method="post">';
echo '<input name="MAX_FILE_SIZE" type="hidden" value="100000">';
echo '<fieldset>';
echo '<legend>Enter the following information to add a show name:</legend>';
echo '<p>Enter Show Name:<input name="showname" type="text"></p>';
echo '<p>Show Type:<select name="type"><option></option><option>Weekly Show</option><option>Pay Per View</option></select></p>';
echo '<p>Upload Show Image:<input name="uploadedfile" type="file"></p>';
echo '<div align="center"><input name="submit" type="submit"><input name="sumbitted" type="hidden" value="TRUE"></div>';
echo '</fieldset>';
echo '</form>';



?>

Link to comment
Share on other sites

well i know that works becuase i have just tested it on your site

 

now you have a problem with ur sql query to fix that

 

// now we insert it into the database
$insert = "INSERT INTO shows (showname, type, showimage) VALUES ('".$_POST['showname']."','".$_POST['type']."','".$_POST['showimage']."')";

$add_show = mysql_query($insert) or die(mysql_error());

 

replace your exsiting code with that

 

i uploaded it seems fine to me

 

http://www.kansasoutlawwrestling.com/images/test.txt

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.