The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.
|
 |
|
Dev Shed Forums
> Programming Languages
> PHP Development
|
Problem with uoloading picture
Discuss Problem with uoloading picture in the PHP Development forum on Dev Shed. Problem with uoloading picture PHP Development forum discussing coding practices, tips on PHP, and other PHP-related topics. PHP is an open source scripting language that has taken the web development industry by storm.
|
|
 |
|
|
|
|

Dev Shed Forums Sponsor:
|
|
|

September 29th, 2012, 02:38 PM
|
|
Registered User
|
|
Join Date: Aug 2012
Posts: 17
Time spent in forums: 5 h 35 m 29 sec
Reputation Power: 0
|
|
|
Problem with uoloading picture
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Upload</title>
</head>
<body>
<form action="upload.php" enctype="multipart/form-data" method="post">
Last Name:<br /> <input type="text" name="name" value="" /><br />
Homework #1:<br /> <input type="file" name="homework1" value="" /><br />
Homework #2:<br /> <input type="file" name="homework2" value="" /><br />
<p><input type="submit" name="submit" value="Submit Notes" /></p>
</form>
<?php
/*echo "that was not correct";
$business_unite = $_POST['name'];
$catergory = $_POST['catergory'];
$image1 = $_POST['image1'];
$image2 = $_POST["image2"];
$services = $_POST["image1"];
$street = $_POST["image1"];
$location = $_POST["location"];
*/
if (isset($_FILES['picture1']) or isset($_FILES['picture2'],$_FILES['picture3']))
{
if (is_uploaded_file($_FILES['image1']['tmp_name']) &&
is_uploaded_file($_FILES['image2']['tmp_name']))
{
if ( ($_FILES['image1']['type'] != "application/gif ||application/png || application/png ||application/jpeg||application/bmp||application/psd application/tif|| application/thm ||application/tuV " ) ||
$_FILES['image2']['type'] != "application/gif ||application/png || application/png ||application/jpeg||application/bmp||application/psd application/tif|| application/thm ||application/tuV " )
{
echo "<p>File format not accepted.</p>";
exit ;
}
/* Format date and create daily directory, if necessary. */
if($new_category){
$path=mkdir("pictures"."/".$category."/".$bissiness_unte);
echo "was not found";
}
else{
$path=mkdir("images/$bussiness_unite");
echo 'was found';
}
function count_files ($dir) { $count = count(glob($_SERVER['DOCUMENT_ROOT'].$dir . "*")) ;
return $count;
}
$image1 = $_POST['name'].$number;
$result = move_uploaded_file($_FILES['Picture1']['tmp_name'],$path);
if ($result == 1) echo "<p> image1 successfully uploaded.</p>";
else echo "<p>There was a problem uploading homework #1.</p>";
/* Name and move homework #2 */
$images2 = $_POST['name']."$number++";
$result = move_uploaded_file($_FILES['Pictures2']['tmp_name'],$path);
if ($result == 1) echo "<p>image2 successfully uploaded.</p>";
else echo "<p>There was a problem uploading homework #2.</p>";
echo "<p>There was a problem uploading homework #1.</p>";
} #endif
}
?>
</body>
</html>
|

September 29th, 2012, 05:55 PM
|
 |
Lord of the Dance
|
|
|
|
Please specify what and where you have problem. Do you get any error message?
One thing you can start to look at is your if statement:
Code:
$_FILES['image1']['type'] != "application/gif || application/png || ...
You will have to specify the variable for each comparison:
Code:
$_FILES['image1']['type'] != "application/gif || $_FILES['image1']['type'] !=application/png || $_FILES['image1']['type'] !=...
When you post code, please use the code tags.
|

September 29th, 2012, 10:48 PM
|
 |
Sarcky
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
westside, please read the new user guide.
__________________
HEY! YOU! Read the New User Guide and Forum Rules
"They that can give up essential liberty to obtain a little temporary safety deserve neither liberty nor safety." -Benjamin Franklin
"The greatest tragedy of this changing society is that people who never knew what it was like before will simply assume that this is the way things are supposed to be." -2600 Magazine, Fall 2002
Think we're being rude? Maybe you asked a bad question or you're a Help Vampire. Trying to argue intelligently? Please read this.
|

October 1st, 2012, 08:05 AM
|
|
Registered User
|
|
Join Date: Aug 2012
Posts: 17
Time spent in forums: 5 h 35 m 29 sec
Reputation Power: 0
|
|
|
when i run the script it shows no error but the upload does not work
when i run the script it shows no error but the upload does not work
|

October 1st, 2012, 08:18 AM
|
 |
Sarcky
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
Did you read the new user guide? I doubt you did.
Your input is named homework1. What is your code looking for?
|

October 1st, 2012, 09:09 AM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 47
Time spent in forums: 11 h 51 m 3 sec
Reputation Power: 2
|
|
For the sake of anyone hoping to answer the question, I am going to repost this code in a more readable format.
PHP Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Upload</title>
</head>
<body>
<form action="upload.php" enctype="multipart/form-data" method="post">
Last Name:<br /> <input type="text" name="name" value="" /><br />
Homework #1:<br /> <input type="file" name="homework1" value="" /><br />
Homework #2:<br /> <input type="file" name="homework2" value="" /><br />
<p><input type="submit" name="submit" value="Submit Notes" /></p>
</form>
<?php
/*echo "that was not correct";
$business_unite = $_POST['name'];
$catergory = $_POST['catergory'];
$image1 = $_POST['image1'];
$image2 = $_POST["image2"];
$services = $_POST["image1"];
$street = $_POST["image1"];
$location = $_POST["location"];
*/
if (isset($_FILES['picture1']) or isset($_FILES['picture2'],$_FILES['picture3']))
{
if (is_uploaded_file($_FILES['image1']['tmp_name']) &&
is_uploaded_file($_FILES['image2']['tmp_name']))
{
if ( ($_FILES['image1']['type'] != "application/gif ||application/png ||
application/png ||application/jpeg||application/bmp||
application/psd application/tif|| application/thm ||application/tuV " ) ||
$_FILES['image2']['type'] != "application/gif ||application/png ||
application/png ||application/jpeg||application/bmp||application/psd
application/tif|| application/thm ||application/tuV " )
{
echo "<p>File format not accepted.</p>";
exit ;
}
/* Format date and create daily directory, if necessary. */
if($new_category){
$path=mkdir("pictures"."/".$category."/".$bissiness_unte);
echo "was not found";
}
else{
$path=mkdir("images/$bussiness_unite");
echo 'was found';
}
function count_files ($dir) {
$count = count(glob($_SERVER['DOCUMENT_ROOT'].$dir . "*")) ;
return $count;
}
$image1 = $_POST['name'].$number;
$result = move_uploaded_file($_FILES['Picture1']['tmp_name'],$path);
if ($result == 1) {
echo "<p> image1 successfully uploaded.</p>";
}
else {
echo "<p>There was a problem uploading homework #1.</p>";
}
/* Name and move homework #2 */
$images2 = $_POST['name']."$number++";
$result = move_uploaded_file($_FILES['Pictures2']['tmp_name'],$path);
if ($result == 1) {
echo "<p>image2 successfully uploaded.</p>";
}
else {
echo "<p>There was a problem uploading homework #2.</p>";
}
echo "<p>There was a problem uploading homework #1.</p>";
} #endif
}
?>
</body>
</html>
|

October 1st, 2012, 09:18 AM
|
 |
Sarcky
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
westside, every line in your code handling the $_FILES array is wrong.
|

October 1st, 2012, 09:24 AM
|
|
Contributing User
|
|
Join Date: Jun 2012
Posts: 47
Time spent in forums: 11 h 51 m 3 sec
Reputation Power: 2
|
|
Now, WESTSIDE200, I can see a few things wrong with your code.
1. You cannot put your comparison operators inside a string
You can't do this:
PHP Code:
$_FILES['image2']['type'] != "application/gif ||application/png || //etc. etc. etc.
Instead, you would have to do this:
PHP Code:
$_FILES['image2']['type'] != "application/gif" && $_FILES['image2']['type'] != "application/png" //etc. etc. etc.
2. You are using inconsistent variable names.
You say in your opening code that $_POST['name'] is set to $business_unite, however, further down you refer to that variable as $bissiness_unte and later on as $bussiness_unite. While we're at it, did you notice that your value transfers ($business_unite = $_POST['name'], etc.) are all commented out?
A few other questions
In order for us to help you out, you'll need to answer a few other questions too.
1. The form in your code has an action set to "upload.php". Is this just a totally unrelated form? Why is it there?
2. The form in the code you posted has no file uploads, yet the php you posted (if related) is checking for them. Why?
3. Why is your initial if statement structured so strangely? (it only passes if the first picture is set, or if BOTH the second and third are set, or if all three are set).
|

October 1st, 2012, 09:34 AM
|
|
Registered User
|
|
Join Date: Aug 2012
Posts: 17
Time spent in forums: 5 h 35 m 29 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by ManiacDan westside, every line in your code handling the $_FILES array is wrong. |
PLEAESE COULD YOU HELP ME CORRECT IT
|

October 1st, 2012, 10:01 AM
|
|
Registered User
|
|
Join Date: Aug 2012
Posts: 17
Time spent in forums: 5 h 35 m 29 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by piperpam27 Now, WESTSIDE200, I can see a few things wrong with your code.
1. You cannot put your comparison operators inside a string
You can't do this:
PHP Code:
$_FILES['image2']['type'] != "application/gif ||application/png || //etc. etc. etc.
Instead, you would have to do this:
PHP Code:
$_FILES['image2']['type'] != "application/gif" && $_FILES['image2']['type'] != "application/png" //etc. etc. etc.
2. You are using inconsistent variable names.
You say in your opening code that $_POST['name'] is set to $business_unite, however, further down you refer to that variable as $bissiness_unte and later on as $bussiness_unite. While we're at it, did you notice that your value transfers ($business_unite = $_POST['name'], etc.) are all commented out?
A few other questions
In order for us to help you out, you'll need to answer a few other questions too.
1. The form in your code has an action set to "upload.php". Is this just a totally unrelated form? Why is it there?
2. The form in the code you posted has no file uploads, yet the php you posted (if related) is checking for them. Why?
3. Why is your initial if statement structured so strangely? (it only passes if the first picture is set, or if BOTH the second and third are set, or if all three are set). |
OK I HAVE WILL TRY TO THE FORM HAS ACTION UPLOAD .PHP SO THAT IT SHOULD SUBMIT THE UPLOAD VARAIBLE TO THE UPLOAD.PHP SCRIPT
|

October 1st, 2012, 10:02 AM
|
 |
Sarcky
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
|
You could try answering any question ever posed to you. Look at the thread, someone went through the effort of giving you two solutions (both of which I asked you direct questions about) and then asked you three more questions.
This is not a resource where you can get experts to write code for you for free, we don't give out work here. Pay someone to do this, or answer the questions that are posed to you.
|

October 1st, 2012, 11:29 AM
|
|
Registered User
|
|
Join Date: Aug 2012
Posts: 17
Time spent in forums: 5 h 35 m 29 sec
Reputation Power: 0
|
|
Quote: | Originally Posted by ManiacDan You could try answering any question ever posed to you. Look at the thread, someone went through the effort of giving you two solutions (both of which I asked you direct questions about) and then asked you three more questions.
This is not a resource where you can get experts to write code for you for free, we don't give out work here. Pay someone torn do this, or answer the questions that are posed to you. |
the form is intended to submit the varaible through post to the same page the page which has the code. and the form takes two files that is homework1 and homework2 so this are the names of the files at the time of upload
i intended to make the first if pass if the the two pictures are set and the second if is intended to gain against a malicious user trying to trick the script
|

October 1st, 2012, 11:59 AM
|
 |
Sarcky
|
|
Join Date: Oct 2006
Location: Pennsylvania, USA
|
|
Get it working first, then add security checks like that (you did the check wrong).
I'm going to ask you this one more time:
Quote: | Your input is named homework1. What is your code looking for? |
|

October 3rd, 2012, 02:27 PM
|
|
Registered User
|
|
Join Date: Aug 2012
Posts: 17
Time spent in forums: 5 h 35 m 29 sec
Reputation Power: 0
|
|
|
thank u all for your contribution the problem has been solve
Last edited by ManiacDan : October 3rd, 2012 at 04:06 PM.
|
Developer Shed Advertisers and Affiliates
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
Rate This Thread |
Linear Mode
|
|
Posting Rules
|
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
HTML code is Off
|
|
|
|
|