Jump to content

[SOLVED] Uploading, renaming, and moving files. Code inside but not working right...


jaxdevil

Recommended Posts

Below is my form for posting to the script 'pdf_upload_test_form.php'

 

<form action="pdf_upload_test.php" method="post" enctype="multipart/form-data" name="form1" id="form1">
File1: <input type="file" name="pdf[]" id="pdf[]"><br>
File2: <input type="file" name="pdf[]" id="pdf[]"><br>
File3: <input type="file" name="pdf[]" id="pdf[]"><br>
Model: <input type="text" name="model_number" id="model_number"><br>
<input type="submit">
</form>

 

 

And below is the script 'pdf_upload_test.php'

 

<?
$path_pdf1= $_SERVER['DOCUMENT_ROOT']."/prod_pdfs/temp/".$HTTP_POST_FILES['pdf']['name'][0];
$path_pdf2= $_SERVER['DOCUMENT_ROOT']."/prod_pdfs/temp/".$HTTP_POST_FILES['pdf']['name'][1];
$path_pdf3= $_SERVER['DOCUMENT_ROOT']."/prod_pdfs/temp/".$HTTP_POST_FILES['pdf']['name'][2];

copy($HTTP_POST_FILES['pdf']['tmp_name'][0], $path_pdf1);
copy($HTTP_POST_FILES['pdf']['tmp_name'][1], $path_pdf2);
copy($HTTP_POST_FILES['pdf']['tmp_name'][2], $path_pdf3);

$orig4_filename = "$path_pdf1";
$new4_filename = $_SERVER['DOCUMENT_ROOT']."/prod_pdfs/".$model_number."-specs.pdf";
$status = rename($orig4_filename, $new4_filename) or exit("Could not add the item");

$orig5_filename = "$path_pdf2";
$new5_filename = $_SERVER['DOCUMENT_ROOT']."/prod_pdfs/".$model_number."-warranty.pdf";
$status = rename($orig5_filename, $new5_filename) or exit("Could not add the item");

$orig6_filename = "$path_pdf3";
$new6_filename = $_SERVER['DOCUMENT_ROOT']."/prod_pdfs/".$model_number."-instructions.pdf";
$status = rename($orig6_filename, $new6_filename) or exit("Could not add the item");

$filesize1=$HTTP_POST_FILES['pdf']['size'][0];
$filesize2=$HTTP_POST_FILES['pdf']['size'][1];
$filesize3=$HTTP_POST_FILES['pdf']['size'][2];

if($filesize1 && $filesize2 && $filesize3 != 0)
{
echo "We have recieved your files";
}

else {
echo "ERROR.....";
}

if($filesize1==0) {
echo "There're something error in your first file";
echo "<BR />";
}

if($filesize2==0) {
echo "There're something error in your second file";
echo "<BR />";
}

if($filesize3==0) {
echo "There're something error in your third file";
echo "<BR />";
}

?>

 

Its not working but also doing something very strange. When I go to use it at /pdf_upload_test_form.php , i select 3 pdf files and type in a model name, it sits for a minute or two while it is sending the data to the script, then the page refreshes, clears all the text in the form fields, and the url then becomes: /pdf_upload_test_form.php/pdf_upload_test.php which is weird in and of itself. Why is it not working first off, and why is it showing it to be in a directory called pdf_upload_test_form.php when that is just the filename?

 

Any ideas?

 

Thanks,

SK

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.