Jump to content

[SOLVED] moving uploaded image!


zang8027

Recommended Posts

Hey, i have a project im working on for class.. i have an addrecords.php page that has a form...It has the enytype and all of that good stuff.

 

Next i have an processadd.php page that recieves the data. Everything works fine with the exception that i have all my images in a folder called images/

 

so when i add my product to the list, the images come up blank because of it.. how can i move the uploaded image file from the root folder to the images folder?  here is the recieve PHP code:

 

my upload boxes are named uthumb and umain

 

 

 

//BEGIN chunk of code to recieve uploaded file from form and place into project folder where image will be placed

$tempFile=$HTTP_POST_FILES['uthumb']['tmp_name'];

$destination=$HTTP_POST_FILES['uthumb']['name'];

copy($tempFile,$destination);

//our own name for this var for use down below

$newthumb=$HTTP_POST_FILES['uthumb']['name'];

 

 

//BEGIN chunk of code to recieve uploaded file from form and place into project folder

$tempFile=$HTTP_POST_FILES['umain']['tmp_name'];

$destination=$HTTP_POST_FILES['umain']['name'];

copy($tempFile,$destination);

//our own name for this var for use down below

$newmain=$HTTP_POST_FILES['umain']['name'];

 

 

 

also, any hints on getting it to pop back an error if my uthumb image is greater than 80x80?  im having it pop back errors for empty fields using an if($newthumn==""){

header("Location:addproduct.php?error=nothumb");

}

 

and using isset on my addrecords page with the get method to pop errors... works fine.

 

 

Link to comment
https://forums.phpfreaks.com/topic/99118-solved-moving-uploaded-image/
Share on other sites

 

<?php
$ff = "destination/";
move_uploaded_file($tempFile, $ff);
?>

 

just change destination to the destination folder you want it to be moved to and it should move it. :) hope this helped. And about checking the dimensions i'm not sure, as I have never really worked with images. :P Another note use the "code" bb codes to display your code. :)

The move_uploaded_file function will take two things... First, the location of the file that was uploaded, so something like $_FILES['umain']['tmp_name'] (or $HTTP_POST_FILES['umain']['tmp_name']. Second it will take the location that you want the files to go to on the server, so something like '/images/main/this.jpg'.

 

move_uploaded_file($HTTP_POST_FILES['umain']['tmp_files'], '/images/main/this.jpg');

move_uploaded_file($HTTP_POST_FILES['uthumb']['tmp_files'}. '/images/thumbs/this.jpg');

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.