Please help me out. I have a form that collects picture from an upload field in a client form and the picture to be printed out on the user page. this work perfectly well on localhost and it looks like the below Ilamini Ayebatonye Thanks A lot
NAME: Name Surname
EMAIL ADDRESS: email@provider.com
HOME ADDRESS: 123 Random Street, FakeTown
PHONE NUMBER: 012345678911
QUALIFICATION: I.C.T Certificate
SECTOR: CCNA
INTEREST: please put in your interest
Please Print this slip, attached your C.V and photocopies of your credentials and come with it to the day of the seminar.
but the problem with is that when I uploaded the site and try registering the picture won't show again,
what i see is the below
ECO9JA-CREATING JOBS IN ICT
Backgrounds_15670_zps11bc080d.png
NAME: Name Surname
EMAIL ADDRESS: email@provider.com
HOME ADDRESS: 123 Random Street, FakeTown
PHONE NUMBER: 012345678911
QUALIFICATION: I.C.T Certificate
SECTOR: CCNA
INTEREST: please put in your interest
Please Print this slip, attached your C.V and photocopies of your credentials and come with it to the day of the seminar.
THANKS FOR REGISTERING
the script is below for the image variable the form upload and the print fxn are as follows:
VARIABLE
<?php
$file= "file.csv";
$name = $_POST['name'];
$email = $_POST['email'];
$address = $_POST['address'];
$phone = $_POST['phone'];
$qualification = $_POST['qualification'];
$sector = $_POST['sector'];
$interest = $_POST['interest'];
$image= $_POST['image'];
<input type="hidden" name="MAX_FILE_SIZE" value="500">
<P>
<br>
<input type="file" name="image" value="upload" >
PRINT THIS CODE ON USERPAGE
<?php print"<img src=\"$image\" width=\"100px\" height=\"100px\"\/>";?>
The problem must lie when you are posting the path for the image file. I have tested the following php with an image "test.png" and it works.
<?php
$image="test.png";
print"<img src=\"$image\" width=\"100px\" height=\"100px\"\/>";
?>
Looks like there is problem with your image attributes, remove "px". it should be like this
<?php print"<img src=\"$image\" width=\"100\" height=\"100\"\/>";?>
Based on Uploading your photo
<input type="file" name="image" value="upload" >
It fetches the file path itself. you could move the uploaded file to your folder and the corresponding file path is to save in db.
If you are uploading the path as looks like
C:\Users\Public\Pictures\Sample Pictures\Desert.jpg
If you are posted as $image = $post['image']
Echo the path it returns to error or null
<img src="C:\Users\Public\Pictures\Sample Pictures\Desert.jpg"/>
If sometimes works but most time won't works as i feel this type of problem.
Thanks.
Based on the reference I commented on your php script you should have a code similar to this:
$allowedExts = array("gif", "jpeg", "jpg", "png");
$temp = explode(".", $_FILES["file"]["name"]);
$extension = end($temp);
if ((($_FILES["file"]["type"] == "image/gif")
|| ($_FILES["file"]["type"] == "image/jpeg")
|| ($_FILES["file"]["type"] == "image/jpg")
|| ($_FILES["file"]["type"] == "image/pjpeg")
|| ($_FILES["file"]["type"] == "image/x-png")
|| ($_FILES["file"]["type"] == "image/png"))
&& ($_FILES["file"]["size"] < 20000)
&& in_array($extension, $allowedExts))
{
if ($_FILES["file"]["error"] > 0)
{
echo "Return Code: " . $_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 "Temp file: " . $_FILES["file"]["tmp_name"] . "<br>";
if (file_exists("upload/" . $_FILES["file"]["name"]))
{
echo $_FILES["file"]["name"] . " already exists. ";
}
else
{
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
}
}
}
else
{
echo "Invalid file";
}
Take a close look line by line. You can set the maximum file size for your image upload at: $_FILES["file"]["size"] < 20000
Furthermore this will code will make sure that the user is uploading an image and not something else.
Finally based on your need and this script after successful upload
move_uploaded_file($_FILES["file"]["tmp_name"],
"upload/" . $_FILES["file"]["name"]);
echo "Stored in: " . "upload/" . $_FILES["file"]["name"];
Then you could do this to show the image:
echo '<img src="upload/'.$_FILES["file"]["name"].'">';
header('Content-Type: image/jpeg');
print $response;
Use this just copy and paste in your project.
$contents= file_get_contents('http://localhost/elgg_social/data/36/641483447202.jpg');
$expires = 14 * 60*60*24;
header("Content-Type: image/jpeg");
header("Content-Length: " . strlen($contents));
header("Cache-Control: public", true);
header("Pragma: public", true);
header('Expires: ' . gmdate('D, d M Y H:i:s', time() + $expires) . ' GMT', true);
echo $contents;
exit;