PDA

View Full Version : Pictures dont display


osti
10-22-07, 10:23 PM
I cant seem to get pictures to display in one of my categories, I am 100% sure that the files are uploading and that everything else is fine.. An example would be at
http://www.ontariosecuritytraining.com/development/home/equipment/category/untitled.php

i tried ping and i tried jpg, gif, mind you some pictures work but not all of them which is extremely weird. I had a powweb techie do something to some images that fided a few of them.


really nothing special here... any help???

Croc Hunter
10-22-07, 10:46 PM
FTP in and goto htdocs/development/home/equipment/category/images/342c.png I think you'll find 342c.png does not exist. If you use your own FTP program images, gif jpg png etc must be uploaded in binary mode.

osti
10-22-07, 11:03 PM
I am using a small upload script below
<form action="modifycat.php?catId= <? echo $catId;?>" method="post" enctype="multipart/form-data">
<table width="100%" border="0" align="center" cellpadding="5" cellspacing="1" class="entryTable">
<tr>
<td width="150" class="label">Category Name</td>
<td class="content"><input name="txtName" type="text" class="box" id="txtName" value="<?php echo $cat_name; ?>" size="30" maxlength="50"></td>
</tr>
<tr>
<td width="150" class="label">Description</td>
<td class="content"> <textarea name="mtxDescription" cols="50" rows="4" class="box" id="mtxDescription"><?php echo $cat_description; ?></textarea></td>
</tr>
<tr>
<td width="150" class="label">Image</td>
<td class="content">
<input name="file" type="file" id="file" class="box">
<?php
if ($cat_image != '') {
$image = 'images/' . $cat_image;
?>
<br>
<img src="<?php echo $image; ?>" width="211" height="140"> &nbsp;&nbsp;<a href="javascript:deleteImage(<?php echo $cat_id; ?>);">Delete
Image</a>
<?php
}
?> </td>
</tr>

</table>
<p align="center">
<input name="btnModify" type="submit" id="btnModify" value="Save Modification" onClick="submit" class="box">
&nbsp;&nbsp;<input name="btnCancel" type="button" id="btnCancel" value="Cancel" onClick="window.location.href='index.php';" class="box">
</p>
</form>

and here is the from handle code
if(isset($_POST['btnModify']))
{

$name = $_POST['txtName'];
$description = $_POST['mtxDescription'];
$catImage = $_FILES["file"]["name"];
$sql = "UPDATE category
SET cat_name = '$name', cat_description = '$description', cat_image = '$catImage'
WHERE cat_id = $catId";

$result = mysql_query($sql) or die('Cannot update category. ' . mysql_error());
if ($_FILES["file"]["error"] > 0)
{
echo "Error: " . $_FILES["file"]["error"] . "<br />";
}
else
{
echo "Upload: " . $_FILES["file"]["name"] . "<br />";
echo "Type: " . $_FILES["file"]["type"] . "<br />";
echo "Size: " . ($_FILES["file"]["size"] / 1024) . " Kb<br />";
echo "Stored in: " . $_FILES["file"]["tmp_name"];
if (file_exists("images/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"images/" . $_FILES["file"]["name"]);
echo "Stored in: " . "images/" . $_FILES["file"]["name"];
}



}





header('Location: index.php?catId='.'$catId'.'&view=list');

entrecon
10-22-07, 11:55 PM
I played around with the format and found that http://www.ontariosecuritytraining.com/development/home/equipment/category/images/342c.gif was there. but not the png

HalfaBee
10-23-07, 05:31 AM
you need to chmod the file to 644 after moving it.

osti
10-23-07, 09:38 PM
I was fooling around and realized that if iupload the image through the FTP the image works but when i upload it using the script it doesnt work,

HalfaBee what you mean by chmod the file to 644 can you please elaborate?

osti
10-23-07, 09:48 PM
OMG HalfaBee I love you man

chmod("/somedir/somefile", 0644);

This **** fixed it all your da man ma friendeven powweb couldnt help wme with this one

osti
10-23-07, 10:01 PM
Happiness short lived, LOL

Warning: chmod() [function.chmod]: No such file or directory

HalfaBee
10-23-07, 10:22 PM
Use "images/" . $_FILES["file"]["name"] as the filename.

You should check the filename for invalid characters before moving the file.
This like * & spaces etc.

osti
10-23-07, 10:31 PM
i just noticed something
i noticed that althought the folder that i upload the images the users have the ability to upload read/write etc
when i upload na image, only the owner has the write to it and not the public

HalfaBee
10-23-07, 10:32 PM
that is what the chmod( ... , 0644 ) fixes.