Page 1 of 1
image uploading problem
Posted: Thu Dec 18, 2003 2:40 pm
by chris12295
I am making an admin section where someone can upload a picture.
They upload it and using getimagesize and imagecreatejpeg i make a thumbnail. Trouble is, it works fine on my local Apache server but when I upload it and run it on the Web Server, i get a message:
Warning: getimagesize(C:\\8.JPG): failed to open stream: No such file or directory in /home/crowncon/public_html/scripts.php on line 136.
what could the problem be?
Posted: Thu Dec 18, 2003 2:43 pm
by DuFF
Could you please post the code? It's hard to know what's causing the error without seeing the upload code.
Posted: Thu Dec 18, 2003 2:44 pm
by Weirdan
you're using the wrong path. Keep in mind that the paths on your development(local) server differs from the paths on production server. Also, perhaps you need to know that *nices use the forward-slash (/) instead of backslash(\) as directory separator.
Posted: Fri Jan 09, 2004 9:09 pm
by chris12295
Here is the code for the function that creates thumbnail and also uploads image:
Code: Select all
function add_pic()
{
if(empty($_REQUESTїpic]))
{
$error = 1;
$GLOBALSїpic_message] = 'Please select a (.JPG) file';
}
if(!$error)
{
$dimensions = getimagesize("$_REQUESTїpic]")or die("Error");
if($dimensionsї2] != 2)
{
$error = 1;
$GLOBALSїpic_message] = "Only use files with .JPG extensions.";
}
}
if(!$error)
{
$width = $dimensionsї0];
$height = $dimensionsї1];
$query = mysql_query("SELECT id from pics");
while($row=mysql_fetch_array($query))
{
$src = $rowїid];
}
$src +=1;
$c = imagecreatetruecolor("$_REQUESTїpic]");
/*y=height x=width*/
$dst_width=(($width*70)/$height);
if($dimensionsї2] == 2)
{
$b = imagecreatetruecolor($dst_width, 70);
$ext = "JPG";
}
if($ext == "JPG")
{
imagecopyresampled($b, $c, 0, 0, 0, 0, $dst_width, 70, $width, $height);
copy("$_REQUESTїpic]", "../images/photos/$src.jpg");
imagejpeg($b, "../images/photos/thumbs/$src.jpg", 100);
}
mysql_query("INSERT into pics (src) VALUES($src)");
$_REQUESTїpic]='';
}
else
{
include("add_pic.php");
die;
}
}
/*_____________________________________________________________________________________________*/
Here is my form code:
Code: Select all
<? include("back.txt"); ?>
<form action="index.php" method="GET">
<table>
<tr><td colspan=3><span class='head1'>Add Picture</span></td></tr>
<tr><td bgcolor="#CCCCCC"><b class='form_text'>Picture File:</b> </td><td bgcolor="#999999"><input type="file" name="pic"></td><td bgcolor="#FFFFFF"><span class="error_message"><?=$GLOBALSїpic_message]?></span></td></tr>
<tr><td bgcolor="#CCCCCC"><b class='form_text'>Add Another Picture:</b> </td> <td bgcolor="#999999"><span class="form_text">Yes</span><input type="checkbox" name="page" value="add_pic" <?if(!empty($_REQUESTїpage]) and !empty($_REQUESTїsubmit])) echo "CHECKED";?>></td><td bgcolor="#FFFFFF"><img src="../images/pix.gif"></td></tr>
<tr><td colspan=2 align='center'><input name="submit" type="submit" value="Add Picture"></td></tr>
<input type="hidden" name="process" value="add_pic">
</table>
</form>
<table cellpadding=0 cellspacing=0 border=0 align='center'>
<tr><td>
<?
$query = mysql_query("SELECT * from pics order by src")or die(MYSQL_ERROR());
$count = 0;
while($row = mysql_fetch_array($query, MYSQL_ASSOC))
{
$count+=1;
$img_src=popup("$rowїsrc]", "admin");
$end = mysql_num_rows($query);
$per_column = ceil($end/2);
if($count == 1)
{
echo "<table cellpadding=5 cellspacing=0 align='left'>";
echo "<tr><td>$img_src</td></tr>\n";
}
elseif($count == $end)
{
echo "<tr><td>$img_src</td></tr>\n</table>";
}
elseif($count % $per_column == 0)
{
echo "<tr><td>$img_src</td></tr>\n</table> \n <table cellpadding=5 cellspacing=0 align='left'>";
}
else
{
echo "<tr><td>$img_src</td></tr>\n";
}
}
echo "\n";
?>
</td></tr>
</table>
<? include("back.txt"); ?>