Jump to content
php.lv forumi

php papildus info


Amerika

Recommended Posts

  • Replies 39
  • Created
  • Last Reply

Top Posters In This Topic

Skripts, kas pārsūta failus uz web servera.

$query3 = "SELECT id FROM news ORDER BY id DESC LIMIT 1";
$data3 = mysql_query ($query3) or die(mysql_error());
$row3 = mysql_fetch_array( $data3 );
$img_type = explode(".", $_FILES['uploaded']['name']);
$image_ext = ($row3['id'] + 1).".".$img_type['1'];



$target = "upload/" . $image_ext;
$target = $target . basename( $_FILES['uploaded']['name']) ;
$ok=1;
$file = $_FILES['uploaded'];
$allowedExtensions = array("jpg", "gif", "png");
function isAllowedExtension($fileName) {
 global $allowedExtensions;

 return in_array(end(explode(".", $fileName)), $allowedExtensions);
}

.....

else
{ if($file['error'] == UPLOAD_ERR_OK) {

if(isAllowedExtension($file['name'])){

if(move_uploaded_file($_FILES['uploaded']['tmp_name'], $target))
{
echo "The file ". basename( $_FILES['uploaded']['name']). " has been uploaded";
}
else
{
echo "Sorry, there was a problem uploading your file.";
}
}  else {
echo "Wrong file type.(.jpg,.png,.gif)";
}
}
else {
echo "Cant upload error $ok = 0";
}
}

iznākumā vēlos lai faila nosaukums atbilstu $image_ext variablim. Liekot bildes iekšā beigās rezultātam vajadzētu būt 1.jpg 2.jpg 3.png utt. Bet nevaru variabli savienot ar move_uploaded_file. Labākajā variantā man sanāca 1.jpgkautkas.jpg

 

Izskatīju vairākus sourcus iespējams, kaut ko palaižu garām visu laiku.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.

×
×
  • Create New...