PDA

View Full Version : File upload


devil123
04-11-2005, 06:11 PM
Hi all,

Finding this old script isnt working on this particular hosting.
The difference is the safe mode is on, i know that move_uploaded_file is affected by this but i cant see why on this script. The image renames are entering into the sql db ok but the pictures arent being moved, renamed, copied, resized at all.
the error message from print_r[$_files] im getting is
Array ( [image1] => Array ( [name] => picture.jpg [type] => image/jpeg [tmp_name] => /tmp/phpcg7jhV [error] => 0 [size] => 65776 but i know error 0 means its uploaded, unfortunately it hasnt. grrrrrrrrrr i looked at the upload_tmp_dir thinking it was possibly the tmp not set to default but it was on default.

Any one got any ideas, been looking at this script what seems like an eon and could do with some fresh eyes.

Cheers all
jay

<?
//------------------- IMAGE UPLOADS ---------------------

$image1 = "";
$image2 = "";
$image3 = "";
$image4 = "";
$image5 = "";
$image6 = "";
$image7 = "";
$image8 = "";
$image9 = "";
$image10 = "";
$image11 = "";
$image12 = "";
$image13 = "";
$image14 = "";
$image15 = "";
$image16 = "";
$image17 = "";
$image18 = "";
$image19 = "";
$image20 = "";


function uploadpics($refnum)
{

global $image1;
global $image2;
global $image3;
global $image4;
global $image5;
global $image6;
global $image7;
global $image8;
global $image9;
global $image10;
global $image11;
global $image12;
global $image13;
global $image14;
global $image15;
global $image16;
global $image17;
global $image18;
global $image19;
global $image20;



$validatefile = 0;

$uploaddir = "temp/";

$invalidfile = 0;

if ($invalidfile == 0){

$indexcount = 1;

for ($indexcount = 1; $indexcount <= 20; $indexcount++){


$sourcefile = "image" . $indexcount;

$dotpos = strrpos($_FILES[$sourcefile]['name'],".");

$fileext = strtolower(substr($_FILES[$sourcefile]['name'],$dotpos + 1));
$imtitle = stripslashes(str_replace("'","",(preg_replace("/\s*/", "", $_POST[itemtitle]))));
$name = $refnum . "_" . $imtitle . "_pic" . $indexcount . "." . $fileext;
$load = $uploaddir . $name;

if ($fileext <> ""){

if ($indexcount == 1){$image1 = $name;}
if ($indexcount == 2){$image2 = $name;}
if ($indexcount == 3){$image3 = $name;}
if ($indexcount == 4){$image4 = $name;}
if ($indexcount == 5){$image5 = $name;}
if ($indexcount == 6){$image6 = $name;}
if ($indexcount == 7){$image7 = $name;}
if ($indexcount == 8){$image8 = $name;}
if ($indexcount == 9){$image9 = $name;}
if ($indexcount == 10){$image10 = $name;}
if ($indexcount == 11){$image11 = $name;}
if ($indexcount == 12){$image12 = $name;}
if ($indexcount == 13){$image13 = $name;}
if ($indexcount == 14){$image14 = $name;}
if ($indexcount == 15){$image15 = $name;}
if ($indexcount == 16){$image16 = $name;}
if ($indexcount == 17){$image17 = $name;}
if ($indexcount == 18){$image18 = $name;}
if ($indexcount == 19){$image19 = $name;}
if ($indexcount == 20){$image20 = $name;}



if (move_uploaded_file($_FILES[$sourcefile]['tmp_name'], $load)) {
} else {
print "File upload failure! Debugging info:\n";
print_r($_FILES);
}

}
}

for ($indexcount = 1; $indexcount <= 20; $indexcount++){
$filedir = "temp/";
$imtitles = stripslashes(str_replace("'","",(preg_replace("/\s*/", "", $_POST[itemtitle]))));
$file = $refnum . "_" . $imtitles . "_pic" . $indexcount . ".jpg";
$filesource = $filedir . $file;

if (is_file($filedir . $file)) {
$imsource = imagecreatefromjpeg($filedir . $file);
$xsource = imagesx($imsource);
$ysource = imagesy($imsource);

if (strpos($file,"pic1") == true){

$yratio = $ysource / $xsource;
$xratio = $xsource / $ysource;

$imdestination = imagecreatetruecolor(100,100 * $yratio);
imagecopyresized($imdestination,$imsource,0,0,0,0,100,100 * $yratio,$xsource,$ysource);
imagejpeg($imdestination,"thumbs/" . $file,120);

}
copy($filesource, "pics/" . $file);
unlink("temp/" . $file);

}}}}
//--------------------------------------------------------------------------------------------------------------------------
if ($_POST[go]) {

include ("");
$validate = 0;
$messstatus="";
$link = mysql_connect ($host, $user, $password);


if ($validate == 0) {

$sql = "INSERT INTO " . $tablename . " (eddate) values ('$eddate')";

if (mysql_db_query($dbname, $sql, $link)) {
$refnum = mysql_insert_id();
}else{
$messstatus = "not inserted " . mysql_error();
}

uploadpics($refnum);

$link = mysql_connect ($host, $user, $password);
$textarea=ereg_replace(10,"<br>",$textarea);
$sql = "UPDATE ". $tablename;
$sql = $sql . " SET itemtitle='" . str_replace("'","",trim($_POST[itemtitle])) . "', details='" . trim($_POST[details]) . "'";
$sql = $sql . ", height='" . trim($_POST[height]) . "', width='" . trim($_POST[width]) . "'";
$sql = $sql . ", sqm='" . trim($_POST[sqm]) . "', weight='" . trim($_POST[weight]) . "'";
$sql = $sql . ", status='" . trim($_POST[status]) . "', category='" . trim($_POST[category]) . "'";
$sql = $sql . ", subcategory='" . trim($_POST[subcategory]) . "', notes='" . trim($_POST[notes]) . "'";

$sql = $sql . ", image20='" . $image20 . "', image19='" . $image19 . "'";
$sql = $sql . ", image18='" . $image18 . "', image17='" . $image17 . "'";
$sql = $sql . ", image16='" . $image16 . "', image15='" . $image15 . "'";
$sql = $sql . ", image14='" . $image14 . "', image13='" . $image13 . "'";
$sql = $sql . ", image12='" . $image12 . "', image11='" . $image11 . "'";
$sql = $sql . ", image10='" . $image10 . "', image9='" . $image9 . "'";
$sql = $sql . ", image8='" . $image8 . "', image7='" . $image7 . "'";
$sql = $sql . ", image6='" . $image6 . "', image5='" . $image5 . "'";
$sql = $sql . ", image4='" . $image4 . "', image3='" . $image3 . "'";
$sql = $sql . ", image2='" . $image2 . "', image1='" . $image1 . "'";

$sql = $sql . ", title20='" . trim($_POST[title20]) . "', title19='" . trim($_POST[title19]) . "'";
$sql = $sql . ", title18='" . trim($_POST[title18]) . "', title17='" . trim($_POST[title17]) . "'";
$sql = $sql . ", title16='" . trim($_POST[title16]) . "', title15='" . trim($_POST[title15]) . "'";
$sql = $sql . ", title14='" . trim($_POST[title14]) . "', title13='" . trim($_POST[title13]) . "'";
$sql = $sql . ", title12='" . trim($_POST[title12]) . "', title11='" . trim($_POST[title11]) . "'";
$sql = $sql . ", title10='" . trim($_POST[title10]) . "', title9='" . trim($_POST[title9]) . "'";
$sql = $sql . ", title8='" . trim($_POST[title8]) . "', title7='" . trim($_POST[title7]) . "'";
$sql = $sql . ", title6='" . trim($_POST[title6]) . "', title5='" . trim($_POST[title5]) . "'";
$sql = $sql . ", title4='" . trim($_POST[title4]) . "', title3='" . trim($_POST[title3]) . "'";
$sql = $sql . ", title2='" . trim($_POST[title2]) . "', title1='" . trim($_POST[title1]) . "'";


$sql = $sql . " WHERE keyindex=" . $refnum ;

if (mysql_db_query($dbname, $sql, $link)) {
$messstatus = "Item added to the Product online database";
}else{
$status = $status . "Failed to add item " . $refnum . mysql_error();
print mysql_error();
}

mysql_close($link);
}}

?>


thanks jay :)

Tangerine Dream
04-12-2005, 05:27 AM
Hi, your PHP code is quite complex. Would you remove parts of the code which are surely not responsible for error :)