webForumDet fria alternativet

Upladdning av filer

PHPur PHP

2 svar · 313 visningar · startad av rincewind

Medlem sedan nov. 2003104 inlägg
Frågan#1

Hej alla,

Jag har lite kod som ser ut som följande

<?
if (!empty($_POST['valueSub'])) 
	{
		// First begin with setting an empty record in the db to get a record id..		
		$sql="insert into tbl_pic(PicWidth, PicHeight) values(0,0)"; 
		mysql_query($sql) or die("Invalid query: " . mysql_error());
		$picID=mysql_insert_id(); // id is picked up here...
		echo "+++>".$_FILES['fileUpload']['tmp_name']."<------";		
		$uploadfile = "img/dbpic/$picID.jpg";
		if (move_uploaded_file($_FILES['fileUpload']['tmp_name'], $uploadfile))
{
    // the the width and height
    $picsize=getimagesize($uploadfile); 
    $imageWidth=$picsize[0];
    $imageHeight=$picsize[1];
//    $imageFilename=?????????????????????? <-- Hur?
		    
    echo "File is valid, and was successfully uploaded($imageWidth, $imageHeight) from file $imageFilename. ";	    
    // After the name, width and height is piced up, we update the db
		    $sql="update tbl_pic set PicWidth=$imageWidth, PicHeight=$imageHeight where PicID=$picID";
		    mysql_query($sql) or die("Invalid query: " . mysql_error()); // After the width and height is piced up, we update the db
		}
		else
		{
		    echo "Possible file upload attack!  Here's some debugging info:\n";
		    print_r($_FILES);
		}
	}
?>
<form enctype=multipart/form-data method=post>
<tr><td>Skicka in bild: </td><td><input type='file' name='fileUpload' size='50'></td></tr>
<tr><td><input type="submit" name="valueSub" value="Skicka in"></td></tr>				
</form>

Jag skulle vilja plocka upp filnamnet också av vad filen hette INNAN den hamnade på servern.
Någon som vet hur man gör detta?=)

Medlem sedan jan. 2003296 inlägg
#2
$_FILES['fileUpload']['name']

...bör det väl vara.

Medlem sedan nov. 2003104 inlägg
#3

hehe.
Så lätt det var..=) Kanske borde läsa på lite om $_FILE..=)
Tackar så mycket jawbreaker!!!

130 ms totalt · 3 externa anrop · v20260731065814-full.4bcf49fe
0 ms — hämta forumlista (cache)
0 ms — hämta statistik (cache)
127 ms — hämta tråd, inlägg och bilagor (db)