Click here to Skip to main content
15,881,248 members
Please Sign up or sign in to vote.
3.00/5 (1 vote)
i making an post private ads
1-> image will upload in server directory
2-> payment via paypal buynow button
3->after payment then will image show echo " <img src="/path/'$img' />
i am not getting problem in upload image in directory then main issue is how to display that particular image that was recently uploaded by that user because there will be more than 10 box so every if user select any of that then image will display on that particular box only
echo $img
.. i think all you got it .. plz help me

Upload image in directory via php code

1-> Upload.form.php

<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">

<title>Upload form</title>
</head>
<body>
<form id="Upload" action="" enctype="multipart/form-data" method="post">
Upload form
<input type="hidden" name="MAX_FILE_SIZE" value="">
<label for="file">File to upload:</label>
<input id="file" type="file" name="file">
<label for="submit">Press to...</label>
<input id="submit" type="submit" name="submit" value="Upload me!">
</form>
</body>
</html>
----------------------------------------------------------------------------------------------

2-> Upload.processor.php

'php.ini max file size exceeded',
2 => 'html form max file size exceeded',
3 => 'file upload was only partial',
4 => 'no file was attached');

// check the upload form was actually submitted else print form
isset($_POST['submit'])
or error('the upload form is neaded', $uploadForm);

// check for standard uploading errors
($_FILES[$fieldname]['error'] == 0)
or error($errors[$_FILES[$fieldname]['error']], $uploadForm);

// check that the file we are working on really was an HTTP upload
@is_uploaded_file($_FILES[$fieldname]['tmp_name'])
or error('not an HTTP upload', $uploadForm);

// validation... since this is an image upload script we
// should run a check to make sure the upload is an image
@getimagesize($_FILES[$fieldname]['tmp_name'])
or error('only image uploads are allowed', $uploadForm);

// make a unique filename for the uploaded file and check it is
// not taken... if it is keep trying until we find a vacant one
$now = time();
while(file_exists($uploadFilename = $uploadsDirectory.$now.'-'.$_FILES[$fieldname]['name']))
{
$now++;
}

// now let's move the file to its final and allocate it with the new filename
@move_uploaded_file($_FILES[$fieldname]['tmp_name'], $uploadFilename)
or error('receiving directory insuffiecient permission', $uploadForm);

// If you got this far, everything has worked and the file has been successfully saved.
// We are now going to redirect the client to the success page.
header('Location: ' . $uploadSuccess);

// make an error handler which will be used if the upload fails
function error($error, $location, $seconds = 5)
{
header("Refresh: $seconds; URL=\"$location\"");
echo ''."\n\n".
'<html lang="en">'."\n".
' <head>'."\n".
' <meta http-equiv="content-type" content="text/html; charset=iso-8859-1">'."\n\n".
' '."\n\n".
' <title>Upload error</title>'."\n\n".
' </head>'."\n\n".
' <body>'."\n\n".
' '."\n\n".
' Upload failure'."\n\n".
' An error has occured: '."\n\n".
' ' . $error . '...'."\n\n".
' The upload form is reloading'."\n\n".
' '."\n\n".
'</html>';
exit;
} // end error handler

?>

-----------------------------------------------------------------------------------------------

3-> Upload.success.php

<html lang="en">
<head>
<meta http-equiv="content-type" content="text/html; charset=iso-8859-1">
<title>Successful upload</title>
</head>
<body>
File upload
Congratulations! Your file upload was successful

</body>
</html>
Posted
Updated 20-Jan-14 22:56pm
v2
Comments
Killzone DeathMan 20-Jan-14 12:28pm    
Just create an paypal account and create there an button for you website, then they provide the code for the button, easy, copy and paste :P
C0DE_007 21-Jan-14 1:35am    
i know that :p but when user pay how will upload process start do you have any code or demo so plzz provide it

If you upload an image with AJAX, you need to return the URL to that image and then insert an img tag pointing to that URL, assuming you saved to the file system.
 
Share this answer
 
Comments
C0DE_007 21-Jan-14 1:37am    
how ?? do you have code .. plzz provide me some small demo or source code ... but bro i dont want to assume i want to attach the uploaded image automatically to img tag
Christian Graus 21-Jan-14 2:37am    
How else did you expect to display it ? Your subject line was confusing. You want to do a paypal step inbetween, that was not clear. Showing an image after you upload it, is trivial. You will need to look at the Paypal API if you intend on going through Paypal in the middle of that process.
C0DE_007 21-Jan-14 3:19am    
bro 1-> step user will select image from there computer ok then image will upload or server directory 2-> then user will click on paypal buynow button after this payment user will get next button or else image will display if user not pay the amont the process will cancel and image will not display... that all if its confusing let we talk only about display image automatically .... or do you have any better way or simple way then plzz tell me it will great for me
Christian Graus 21-Jan-14 3:22am    
Displaying the image automatically is still trivial. Step 1 -> upload image. Step 2 -> add img tag pointing to image file to your HTML. But, if you want to do stuff that involves the Paypal API, then you have to read their docs to see what they support. If your header had been clear, I would not have answered, I know nothing about paypal integration
C0DE_007 21-Jan-14 3:29am    
how ..? i want to pointing the image file name to image tag automatically .... do you have any demo of this or please provide me source code
This is code for getting image file name and display after uploading to directory

<img src="<?php echo "../upload/$image" ?>" >

$image = $_FILES["file"]["name"]; move_uploaded_file($_FILES["file"]["tmp_name"],"../upload/$image"); $query = "INSERT INTO images VALUES('','$image')";
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900