 |
Account Login
|
 |
 |
Latest Articles
|
 |
 |
IRC Channel
|
 |
 |
Associates
|
 |
 |
Associates
|
 |
|
 |
 |
|
 |
02-25-2008, 02:33 AM
|
#1 (permalink)
|
|
The Wanderer
Join Date: Feb 2008
Posts: 13
Thanks: 3
|
Host Upgraded - File Upload won't work now
I have had my site working for MANY years until recently my host had upgraded the server to PHP 5. Sicne then I can't get a simple file upload to work? Can anyone look at this code and tell me why it wouldn't work?
The error I am getting is " Sorry. You did not chose an image" which I am assuming means the file string isn't being passed on??? But the weirder thing is I am getting the "Ad uploaded" message also? So it's telling me there is an error but also saying it was uploaded (which it isn't).
PHP Code:
<?php
$adtitle = $_POST['adtitle'];
$adtype = $_POST['adtype'];
$imagetype = $_POST['imagetype'];
$adimagefile = $_POST['adimagefile'];
$url = $_POST['url'];
$groupid = $_POST['groupid'];
$error = false;
$errormessage = "";
if (strlen($adtitle) < 1) {
$error = true;
$errormessage .= "<li><b>Sorry. You did not enter an ad title.</b><br>\n";
}
if ($adtype == 'A'){
if (strlen($code) < 1) {
$error = true;
$errormessage .= "<li><b>Sorry. You did not enter an affiliate code.</b><br>\n";
}
}
if ($adtype == 'O'){
if (strlen($adimagefile) < 1) {
$error = true;
// HERE"S MY ERROR!!!!!
$errormessage .= "<li><b>Sorry. You did not chose an image</b><br>\n";
}
if ($imagetype == "") {
$error = true;
$errormessage .= "<li><b>Sorry. You did not chose an image type.</b><br>\n";
}
if (strlen($url) < 1) {
$error = true;
$errormessage .= "<li><b>Sorry. You did enter a URL</b><br>\n";
}
}
?>
<h2>Save new ad</h2>
<p>
<?php
$adid = nextid("ads", "adid");
if($adtype == 'O'){
// HERE's MY UPLOAD
$newfilename = "../ads/$adid.$imagetype";
$picfile = $HTTP_POST_FILES['userfile']['tmp_name'];
copy($adimagefile, $newfilename);
printf("Ad uploaded<br>");
}
if ($error) {
printf("<font color=red>There was a problem creating the ad!</font><br><br>Please click on back in your browser to fix the problems listed below.<br>");
printf($errormessage);
} else {
if ($adtype == 'A'){
$sql = "insert into ads (adid, code, impressions, clicks, groupid, type, name) values ($adid, '$code', 1, 1, $groupid, '$adtype', '$adtitle')";
}
if ($adtype == 'O'){
$newurl = "http://";
$newurl .= $url;
$sql = "insert into ads (adid, image, url, impressions, clicks, groupid, type, name) values ($adid, '$imagetype', '$newurl', 1, 1, $groupid, '$adtype', '$adtitle')";
}
$result = mysql_query($sql ,$db);
printf("<p>The ad has been added to the group.</p>");
printf("<p><a href=editadgroup.php?groupid=$groupid>Back to ad group</a></p>");
}
?>
</p>
|
|
|
|
02-25-2008, 02:47 AM
|
#2 (permalink)
|
|
The Contributor
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
|
Try this code:
PHP Code:
if($adtype == 'O'){
// HERE's MY UPLOAD
$newfilename = "../ads/$adid.$imagetype";
$picfile = $HTTP_POST_FILES['userfile']['tmp_name'];
if ( move_uploaded_file( $picfile, $newfilename) ) {
printf("Ad uploaded<br>");
} else {
printf( "Ad not uploaded");
}
}
Also:
PHP Code:
if (!empty($adimagefile))
or
PHP Code:
if (isset($adimagefile)) {
see how this works for you.
Did you try
PHP Code:
print_r( $_POST );
to see is the $_POST variables are all there?
Can you tell us how does it work. is this the upload-add script or?
__________________
Back from sysadmins to the programmers.
|
|
|
02-25-2008, 02:56 AM
|
#3 (permalink)
|
|
The Wanderer
Join Date: Feb 2008
Posts: 13
Thanks: 3
|
this is a custom CMS backend to add advetisement banners to my website but of course now it's not working. My assumption is that PHP5 uses move_file_uploaded now instead of copy?
Ok. still didn't work. Again saying i didn't select an image? i added a var_dump(@POST); to my script and the image file is not being passed through by the script? here's my form that is submiting the info is there a problem with this maybe?
HTML Code:
<form enctype="multipart/form-data" action=savead.php method=post>
<p>
<input type=hidden name=adtype value="O">
<input type=hidden name=groupid value="2">
Title<br><input type=text name=adtitle size=50>
<br>
Upload Ad<br><input type="hidden" name="MAX_FILE_SIZE" value="100000" />
<input name="adimagefile" type="file">
<br>
image type<br><input type="radio" name="imagetype" value="jpg"> - Jpeg <input type="radio" name="imagetype" value="gif">Gif<br>
URL<br>
http://<input type=text name=url size=50>
<br>
<input type=reset value=Reset>
<input type=submit value=Submit>
</p>
</form>
here's my $_POST variables...
PHP Code:
Array ( [adtype] => O [groupid] => 2 [adtitle] => Test Title [MAX_FILE_SIZE] => 100000 [imagetype] => jpg [url] => www.google.com )
No $adimagefile
|
|
|
|
02-25-2008, 03:20 AM
|
#4 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,258
Thanks: 90
|
Uploaded items get stored in $_FILES, not $_POST.
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
02-25-2008, 03:20 AM
|
#5 (permalink)
|
|
The Contributor
Join Date: Feb 2008
Location: Croatia
Posts: 90
Thanks: 4
|
Edit: hehe Wildhoney - same post time :)
-----
oh.
YOu don't get 'adimagefile' in the $_POST -
there should on be adtitle, imagetype and url.
The adimagefile data, e.g. the data about the uploaded image is in $_FILES['adimagefile'].
Here's an array
PHP Code:
$file = array( 'tmp_name' => $_FILES['adimagefile']['name'], 'tmp_type' => $_FILES['adimagefile']['type'], 'tmp_file' => $_FILES['adimagefile']['tmp_name'], 'tmp_size' => $_FILES['adimagefile']['size'] );
And there you have : - tmp_name => the name of the file - (image1.jpg/image1.gif)
- tmp_type => the type - image/jpeg, image/gif, image/png
- tmpl_file => the path to the tmp file created by php in the tmp folder :)
- tmp_size => the size of the image
Hope this works for you:
PHP Code:
<?php $adtitle = $_POST['adtitle']; $adtype = $_POST['adtype']; $imagetype = $_POST['imagetype']; $url = $_POST['url']; $groupid = $_POST['groupid']; $file = array( 'tmp_name' => $_FILES['adimagefile']['name'], 'tmp_type' => $_FILES['adimagefile']['type'], 'tmp_file' => $_FILES['adimagefile']['tmp_name'], 'tmp_size' => $_FILES['adimagefile']['size'] );
$error = false; $errormessage = "";
if (strlen($adtitle) < 1) { $error = true; $errormessage .= "<li><b>Sorry. You did not enter an ad title.</b><br>\n"; } if (strlen($url) < 1) { $error = true; $errormessage .= "<li><b>Sorry. You did enter a URL</b><br>\n"; }
} if (strlen($code) < 1) { $error = true; $errormessage .= "<li><b>Sorry. You did not enter an affiliate code.</b><br>\n"; } if ( !$error ) { echo "<h2>Save new ad</h2> <p>"; if ( $file['tmp_type'] == 'image/jpeg' | $file['tmp_type'] == 'image/gif') { // Upload $newfilename = "../ads/$adid.$imagetype"; $picfile = $file['tmp_file']; if ( move_uploaded_file( $picfile, $newfilename) ) { printf("Ad uploaded<br>"); // Add to the DB switch ( $adtype) { case 'A': $sql = "insert into ads (adid, code, impressions, clicks, groupid, type, name) values ($adid, '$code', 1, 1, $groupid, '$adtype', '$adtitle')"; break; // Right ad - upload and add to the DB case 'O': $newurl = "http://"; $newurl .= $url; $sql = "insert into ads (adid, image, url, impressions, clicks, groupid, type, name) values ($adid, '$imagetype', '$newurl', 1, 1, $groupid, '$adtype', '$adtitle')"; break; } $result = mysql_query($sql ,$db); if ( $result ) { printf("<p>The ad has been added to the group.</p>"); printf("<p><a href=editadgroup.php?groupid=$groupid>Back to ad group</a></p>"); } else { printf( "Error inserting into the DB"); } } else { printf( "Ad not uploaded"); } echo "</p>"; } else { printf "<li><b>Sorry. You did not chose an image</b><br>\n"; } } else { printf("<font color=red>There was a problem creating the ad!</font><br><br>Please click on back in your browser to fix the problems listed below.<br>"); printf($errormessage); }
__________________
Back from sysadmins to the programmers.
|
|
|
|
The Following User Says Thank You to abiko For This Useful Post:
|
|
02-25-2008, 03:23 AM
|
#6 (permalink)
|
|
The Wanderer
Join Date: Feb 2008
Posts: 13
Thanks: 3
|
should this be taken out then?
PHP Code:
$adimagefile = $_POST['adimagefile'];
|
|
|
|
02-25-2008, 03:30 AM
|
#7 (permalink)
|
|
La Vida es Sueño
Join Date: Sep 2007
Location: Oldham
Posts: 2,258
Thanks: 90
|
It should be like the following:
php Code:
$adimagefile = $_FILES['adimagefile'];
Then you'll have like:
php Code:
$adimagefile['tmp_name']; $adimagefile['name']; $adimagefile['size'];
Edit: Hehe, abiko!
__________________
The man who comes back through the Door in the Wall will never be quite the same as the man who went out.
|
|
|
|
The Following User Says Thank You to Wildhoney For This Useful Post:
|
|
02-25-2008, 03:53 AM
|
#8 (permalink)
|
|
The Wanderer
Join Date: Feb 2008
Posts: 13
Thanks: 3
|
thanks! Got it working. 
|
|
|
|
|
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
|
|
|
| Thread Tools |
Search this Thread |
|
|
|
| Display Modes |
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
|
|
|
|