|
-
Jun 2nd, 2007, 12:27 AM
#1
Thread Starter
WiggleWiggle
Uploading Image, Naming Problem
I have this upload page, and when it uploads, it just uploads the file, as a file, not a picture, with no extention. Here is my code:
PHP Code:
if($_POST["action"] == "Upload Image"){
unset($imagename);
$memberid = $_SESSION['member_id'];
if(!isset($_FILES) && isset($HTTP_POST_FILES))
$_FILES = $HTTP_POST_FILES;
if(!isset($_FILES['image_file']))
$error["image_file"] = "An image was not found.";
#One Directory for ALL pics, random filename
$rand1 = rand(1, 99);
$rand2 = rand(100, 999);
$rand3 = rand(1000, 9999);
$rand = $rand3 - $rand2 + $rand1;
$imagename = $memberid . "_" . $rand;
/*
#One dir for each member, original file names, or random is file name doesnt exitst
$imagename = basename($_FILES['image_file']['name']);
if(empty($imagename))
$rand1 = rand(1, 99);
$rand2 = rand(100, 999);
$rand3 = rand(1000, 9999);
$rand = $rand3 - $rand2 + $rand1;
$imagename = $memberid . "_" . $rand;
*/
if(empty($error))
{
$newimage = "pics/" . $imagename;
//$newimage = "pics/$memberid/" . $imagename;
//echo $newimage;
$result = @move_uploaded_file($_FILES['image_file']['tmp_name'], $newimage);
if(empty($result)) {
$error["result"] = "There was an error moving the uploaded file.";
} else {
$url = "http://pics.rapidfriends.com/" . $imagename;
$sql1 = "SELECT `picture_id` FROM `pictures` WHERE member_id='$memberid'";
$query1 = mysql_query($sql1);
$num = mysql_num_rows($query1);
if ($num == "0") {
$sql2 = "UPDATE `members` SET `default_pic_url`='$url' WHERE member_id='$memberid'";
$query2 = mysql_query($sql2);
}
$caption = $_POST['caption'];
$sql = "INSERT INTO `pictures` SET url='$url', member_id='$memberid', caption='$caption'";
$query = mysql_query($sql);
echo mysql_error();
echo "Your Picture Was successfuly Uploaded:<br><br>";
include("includes/functions.php");
$showimg = getimagesize($url);
$imgtag = imageResize($showimg[0], $showimg[1], 150);
echo "<img src='$url' title='$caption' $imgtag><br><br>Direct URL: $url<br><br><br>";
}
}
}
in the db, the url is as follows: http://pics.rapidfriends.com/13_6510
notice no extention, and it still goes to a picture, with the jpeg format... I dont understand whats going wrong...
My usual boring signature: Something
-
Jun 2nd, 2007, 01:06 PM
#2
Re: Uploading Image, Naming Problem
uhh, maybe because you're making the image file's name like this?
PHP Code:
$imagename = $memberid . "_" . $rand;
//............
$newimage = "pics/" . $imagename;
if YOU don't add the extension, it won't be there. you can use this:
PHP Code:
$file = $_FILES['image_file']['tmp_name'];
$pos = strrpos($file, '.');
$extension = substr($file, $pos, strlen($file) - $pos);
$imagename .= "{$memberid}_{$rand}{$extension}";
-
Jun 2nd, 2007, 06:19 PM
#3
Thread Starter
WiggleWiggle
Re: Uploading Image, Naming Problem
why are there brackets in the string?
My usual boring signature: Something
-
Jun 7th, 2007, 03:49 PM
#4
Re: Uploading Image, Naming Problem
curly brackets within a string denote using a variable. this avoids having to break your string or escape something when you don't need to.
PHP Code:
<?php
//example 1:
echo "$this['array']['wont']['print']";
echo "{$this['array']['will']}";
//example 2:
$var1 = 'string';
$var2 = 'text';
//the following will not print as expected:
echo "$var1_$var2";
//PHP will be looking for a variable named either "$var1_" and "$var2", or just one variable named "$var1_text". ("text" comes from adding $var2's actual value onto the variable reference because there is no space)
//the following will print as expected:
echo "{$var1}_{$var2}";
?>
hope that made sense @_@
-
Jun 7th, 2007, 05:33 PM
#5
Thread Starter
WiggleWiggle
Re: Uploading Image, Naming Problem
oh ok. That makes sense thanks!
My usual boring signature: Something
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|