Help....Unable to upload pdf files by uploader
Started on the old forum in September 2013 · view the original in the archive · old links redirect here
TL;DR · summary of 11 replies
- The PHP script was not uploading PDF files due to errors.
- The code needed changes for security, such as setting correct file permissions and ensuring proper directory paths were used.
- After editing the upload.php script with Ghost's advice, zong11 encountered another error: Parse error on line 90 of C:\xampp\htdocs\upload2.php.
- A modified version of a previous uploader was suggested by Ghost for use.
Written automatically from the replies by a language model on our own server. It can be wrong; the posts below are the source.
zong11 wrote: hey please help me i am trying to upload files using uploader in chintans sea script but files does not uploads. It replies as
An error has occured: Error in copy source file.. ... The upload form is reloading...
Copy & Paste the php source of the file which gave this error
I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID
softwarefreak wrote: Copy & Paste the php source of the file which gave this error
Always Help Needy Peoples !!!!!
zong11 wrote: http://ijppsjournal.com/Vol%201%20Issue%201/117.pdf
The source of the php script brother, It must be something called upload.php
I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID
softwarefreak wrote: The source of the php script brother, It must be something called upload.php
<?php
/*
$image_name = 'call';
$fh = fopen("tmp_crawl.php", 'w') or die("can't open file");
$stringData = $image_name;
fwrite($fh, $stringData);
fclose($fh);
@extract($_REQUEST);
$filename = $_FILES['file']['name'];
$temp_name = $_FILES['file']['tmp_name'];
$error = $_FILES['file']['error'];
$size = $_FILES['file']['size'];
/* NOTE: Some server setups might need you to use an absolute path to your "dropbox" folder
(as opposed to the relative one I've used below). Check your server configuration to get
the absolute path to your web directory*/
/* if(!$error)
move_uploaded_file($temp_name, '../../../folder/'.$filename);
echo '1';
*/
?>
<?php
$errors = array();
$data = "";
$success = "false";
function return_result($success,$errors,$data) {
echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
?>
<results>
<success><?=$success;?></success>
<?=$data;?>
<?=echo_errors($errors);?>
</results>
<?
}
function echo_errors($errors) {
for($i=0;$i<count($errors);$i++) {
?>
<error><?=$errors[$i];?></error>
<?
}
}
switch($_REQUEST['action']) {
case "upload":
$file_temp = $_FILES['file']['tmp_name'];
$file_name = $_FILES['file']['name'];
$file_new_name = $_REQUEST['newName'].'.'.pathinfo($file_name, PATHINFO_EXTENSION);
$file_path = '../../../folder';
//checks for duplicate files
if(!file_exists($file_path."/".$file_name)) {
//complete upload
$filestatus = move_uploaded_file($file_temp,$file_path."/".$file_new_name);
if(!$filestatus) {
$success = "false";
array_push($errors,"Upload failed. Please try again.");
}
}
else {
$success = "false";
array_push($errors,"File already exists on server.");
}
break;
default:
$success = "false";
array_push($errors,"No action was requested.");
}
return_result($success,$errors,$data);
?>
Always Help Needy Peoples !!!!!
ok, you've to make change here
$file_path = '../../../folder';
I blv the path given does not exists, replace it w/ the absolute path of the directory where you want to upload files, also it must have have permission to write & execute so chmod it to 777
The script is very much unsafe, you shudn't use to to allow users upload files
I need some facebook likes, can you please help me 🤝 http://facebook.com/softwarefreakin I noticed social media is really powerful 🧙 Well DONE is better than well SAID
softwarefreak wrote: ok, you've to make change here
$file_path = '../../../folder';I blv the path given does not exists, replace it w/ the absolute path of the directory where you want to upload files, also it must have have permission to write & execute so chmod it to 777
The script is very much unsafe, you shudn't use to to allow users upload files
thanks dear..
Always Help Needy Peoples !!!!!
if the file your using this code in is located in public_html folder then you only need something like this: $file_path = 'path/to/upload/folder'; example: $file_path = 'upload_file';
if the file your using code in is in a folder then you need to use the ../ to specify going down to public_html then up to located folder.
example located in folder. public_html/a_folder/upload.php <-- upload file location. public_html/upload_file <-- uploaded files (folder location)
so the outcome would be down 1 lvl to public html with "../" and then up to folder location like so: $file_path = '../upload_file';
if you still need more help/info. then post location of your upload.php file. and also location of uploaded files folder.
Ghost wrote: if the file your using this code in is located in public_html folder then you only need something like this: $file_path = 'path/to/upload/folder'; example: $file_path = 'upload_file';
if the file your using code in is in a folder then you need to use the ../ to specify going down to public_html then up to located folder.
example located in folder. public_html/a_folder/upload.php <-- upload file location. public_html/upload_file <-- uploaded files (folder location)
so the outcome would be down 1 lvl to public html with "../" and then up to folder location like so: $file_path = '../upload_file';
if you still need more help/info. then post location of your upload.php file. and also location of uploaded files folder.
location of my upload.php public_html/myadmin/category/uploader/upload.php
and location of uploaded files folder is
public_html/upload_file.
and this is my upload.php plz edit this
<?php
/*
$image_name = 'call';
$fh = fopen("tmp_crawl.php", 'w') or die("can't open file");
$stringData = $image_name;
fwrite($fh, $stringData);
fclose($fh);
@extract($_REQUEST);
$filename = $_FILES['file']['name'];
$temp_name = $_FILES['file']['tmp_name'];
$error = $_FILES['file']['error'];
$size = $_FILES['file']['size'];
/* NOTE: Some server setups might need you to use an absolute path to your "dropbox" folder
(as opposed to the relative one I've used below). Check your server configuration to get
the absolute path to your web directory*/
/* if(!$error)
move_uploaded_file($temp_name, '../../../upload_file/'.$filename);
echo '1';
*/
?>
<?php
$errors = array();
$data = "";
$success = "false";
function return_result($success,$errors,$data) {
echo("<?xml version=\"1.0\" encoding=\"utf-8\"?>");
?>
<results>
<success><?=$success;?></success>
<?=$data;?>
<?=echo_errors($errors);?>
</results>
<?
}
function echo_errors($errors) {
for($i=0;$i<count($errors);$i++) {
?>
<error><?=$errors[$i];?></error>
<?
}
}
switch($_REQUEST['action']) {
case "upload":
$file_temp = $_FILES['file']['tmp_name'];
$file_name = $_FILES['file']['name'];
$file_new_name = $_REQUEST['newName'].'.'.pathinfo($file_name, PATHINFO_EXTENSION);
$file_path = '../../../upload_file';
//checks for duplicate files
if(!file_exists($file_path."/".$file_name)) {
//complete upload
$filestatus = move_uploaded_file($file_temp,$file_path."/".$file_new_name);
if(!$filestatus) {
$success = "false";
array_push($errors,"Upload failed. Please try again.");
}
}
else {
$success = "false";
array_push($errors,"File already exists on server.");
}
break;
default:
$success = "false";
array_push($errors,"No action was requested.");
}
return_result($success,$errors,$data);
?>
upon editing it replies as
An error has occured: Error in copy source file.. ... The upload form is reloading...
If u want any more info plz suggest me. Thanks
Always Help Needy Peoples !!!!!
it would seem the file/folder location is not the problem. that code/script is riddled with many issues. no security, bad use of short tags, badly closed coding. and much more. i cant even get the script to run as is. without fixing these things first. the error i get from this is:
Parse error: syntax error, unexpected end of file in C:\xampp\htdocs\upload2.php on line 90
it would be in your best interest to find something better.
i could pull out my old uploader i made for my community script modify it a little so your able to use that standalone. i have made a second uploader for my newest project but not quite finished yet to be able to let anyone have it. and besides i want it in my script before other peoples. but my 1st uploader should be good enough.
here is my uploader,
<?php
$Allowed_File_Types = array('zip', 'rar', 'pdf', '', '', '', '');
$Max_File_Size = 2097152; /** 2MB */
$Upload_Path = 'upload_file';
if(isset($_POST['upload_file'])) {
function Upload($Upload_Path, $Allowed_File_Types, $Max_File_Size) {
$File_Name = strtolower($_FILES['file']['name']);
$Array = explode('.', $File_Name);
$Extension = end($Array);
if($File_Name == '') {
return 'It would seem you did not add a file to upload. please try again.';
}
elseif(!in_array($Extension, $Allowed_File_Types)) {
return 'The file you attempted to upload is not allowed.';
}
elseif(filesize($_FILES['file']['tmp_name']) > $Max_File_Size) {
return 'The file you attempted to upload is too large.';
}
elseif(!is_writable($Upload_Path)) {
return 'You cannot upload to the directory.<br/>please make sure the upload path exists, pointed correctly to<br/>or folder permissions is set correctly to 755 or 777.';
}
elseif(file_exists($Upload_Path.'/'.$File_Name)) {
$New_File_Name = rand(0, 99999).' '.$File_Name;
move_uploaded_file($_FILES['file']['tmp_name'], $Upload_Path.'/'.$New_File_Name);
return '<u>Your file was successfully uploaded.</u><br/>There was a filename conflict with one of the existing files<br/>so we modfied the file name slightly with a random number<br/><br/>Download Location: <a href="http://'.$_SERVER['SERVER_NAME'].'/'.str_replace('../', '', $Upload_Path).'/'.$New_File_Name.'">http://'.$_SERVER['SERVER_NAME'].'/'.str_replace('../', '', $Upload_Path).'/'.$New_File_Name.'</a>';
}
elseif(move_uploaded_file($_FILES['file']['tmp_name'], $Upload_Path.'/'.$File_Name)) {
return '<u>Your file was successfully uploaded.</u><br/><br/>Download Location: <a href="http://'.$_SERVER['SERVER_NAME'].'/'.str_replace('../', '', $Upload_Path).'/'.$File_Name.'">http://'.$_SERVER['SERVER_NAME'].'/'.str_replace('../', '', $Upload_Path).'/'.$File_Name.'</a>';
} else {
return 'There was an error during the file upload. Please try again.';
}
}
echo Upload($Upload_Path, $Allowed_File_Types, $Max_File_Size);
//echo '<br/><br/><a href="index.php">Home</a><br/>';
} else {
echo '<form enctype="multipart/form-data" action="upload.php" method="post">';
echo 'Upload File: ';
echo '<input class="input-style" type="file" name="file" />';
echo '<input class="button-style" type="submit" name="upload_file" value="Upload File" />';
echo '</form>';
//echo '<br/><a href="index.php">Home</a><br/>';
}
?>
i have modified it to give you a download link after uploading file, i have modded it to allow zip, rar, pdf files. it allows files 2mb or lower atm, you can change this yourself. i have also modded it so you have upload form and upload code in same file.
all you need to do really is set the $Upload_Path = 'upload_file'; depending on where you use the file/code, atm is set to work from public_html. but you can change that easily if put inside folder by adding ../ like explained before.
this is 100% tested and working.
zong11 wrote: script is enabled for pc upload i want to uplaod online pdf link as like url upload
well im pretty sure you can change the html form to an input text form and name it the same as this form EI: name="file" if you just try.. the script is working fine and will work with either normal form or an upload form. if you just give it a try.