We're a community of 1077K IT Pros here for help, advice, solutions, professional growth and fun. Join us!
1,076,322 Members — Technology Publication meets Social Media
Username:
Password:
Lost login information?
Start New Discussion Reply to this Discussion

PHP image file upload issue

Hi

I have had a client asking me to look at the image upload section of the site i have built for them:

Here is the upload form code:

<form enctype="multipart/form-data" action="processupload.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000" />
<center>Choose photo to upload: <input name="uploadedfile" type="file" /><br><br>
<input type="submit" value="Go to next step >>" /><center>
</form>

Here is the processing of the upload:

<?php

session_start();

// Where the file is going to be placed
$target_path = "images/";

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path.basename($_FILES['uploadedfile']['name']);
$target_path = "images/";

$target_path = $target_path.basename($_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
   $message ="The file ".basename($_FILES['uploadedfile']['name'])."has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

header("Location: addcontact.php?file=$target_path");

?>

Here is the code to update the file once uploaded:

<form enctype="multipart/form-data" action="changephotouploadprocess.php" method="POST">
<input type="hidden" name="MAX_FILE_SIZE" value="100000000000" />
<center>Choose photo to upload: <input name="uploadedfile" type="file" /><br><br>
<input type="text" name="id" value="<?php echo $_SESSION['id']; ?>">
<input type="text" name="oldfilename" value="<?php echo $_SESSION['oldfilename']; ?>">



<?php
session_start();

$id = $_GET['id'];
$oldfilename = $_GET['oldfilename'];

// Where the file is going to be placed
$target_path = "images/";

/* Add the original filename to our target path.
Result is "uploads/filename.extension" */
$target_path = $target_path.basename($_FILES['uploadedfile']['name']);
$target_path = "images/";

$target_path = $target_path.basename($_FILES['uploadedfile']['name']);

if(move_uploaded_file($_FILES['uploadedfile']['tmp_name'], $target_path)) {
   $message ="The file ".basename($_FILES['uploadedfile']['name'])."has been uploaded";
} else{
    echo "There was an error uploading the file, please try again!";
}

header("Location: confirmupdate.php?file=$target_path");

?>

I am having the problem where some image files are not uploading or updating.

I am not sure what is going on and I am very desperate to fix the issue.

Please can someone help?

2
Contributors
3
Replies
1 Hour
Discussion Span
10 Months Ago
Last Updated
5
Views
chris_j_haines
Light Poster
35 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

I am having the problem where some image files are not uploading or updating.

Can you be more specific? Certain formats, certain sizes, certain names?

diafol
Keep Smiling
Moderator
10,668 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57

I have a feeling it is due to the name of the file as i have managed to upload some files in different image file types such a png, jpg and gif but some with different filenames do not i am not too sure about file sizes though

chris_j_haines
Light Poster
35 posts since Aug 2008
Reputation Points: 10
Solved Threads: 0
Skill Endorsements: 0

Again, sorry Chris, but could you be more specific with the files that are causing errors, e.g. filenames, sizes. Otherwise we're just guessing (unless somebody's seen something obviously wrong in the code).

diafol
Keep Smiling
Moderator
10,668 posts since Oct 2006
Reputation Points: 1,632
Solved Threads: 1,514
Skill Endorsements: 57

This article has been dead for over three months: Start a new discussion instead

Post: Markdown Syntax: Formatting Help
 
You
 
© 2013 DaniWeb® LLC
Page rendered in 0.0679 seconds using 2.69MB