Upload a pdf file without the actuall upload - php

Ones again I have a question which I hope to get help with.
I have a small database where I want to include information about the location of specific pdf files. This means that I am not saving the actual pdf’s just their location on a local drive.
The issue is that I don’t need to do any upload of the file since they are located where I want them to be beforehand.
My actual form code is a type="file" code with a browser button. It saves a copy of the pdfs into pdffiles map. What I want is to keep the browser button functionality but without the need of saving the files in the pdffiles map, plus that I want the saved pathway in Mysql code to be the original location of the file.
I hope you can understand what I am trying to achieve.
Thanks to you all!
Unfortunately, my knowledge in JavaScript is limited.
The form line I am trying to read is simple:
Say I have a file: C:\test\Ritningsregister\pdffile1.pdf
Like I said before all I want is to store the path info of the current file into MySql without any upload/download involved. I have been trying to use pathinfo($_FILES['filename']['name'], PATHINFO_DIRNAME) but it only gives me the relative path, ie .
pathinfo($_FILES['filename']['name'], PATHINFO_BASENAME) returns pdffile1.pdf as it should.
I have also trying to use realpath($_FILES['filename']['name']) hoping it will give me the whole path information: C:\test\Ritningsregister\ … without any luck.
What I at least could establish is that when I am trying to open a pdf file whose pathway has beforehand been imputed into MySQL say: C:/test/Ritningsregister/pdffile1.pdf. The browser had no problem in opening it.
So I really hope you can help me to solve this problem!
Best regards CaLey

[edit]
well what you could do then is use javascript to grab the value from the input-file and put that text into the value of a hidden input, and then reset the input-file so no file is uploaded. if you need help working out how to do this let me know :)
[edit]
are you just trying to process some file locations into a database ? as you can use php scripting to just read a directory's file's and then save that into a db without a form at all

Related

Using JQuery or PHP to pull latest image?

I was trying to figure out a way to have JQuery (if possible) to display the latest image from a directory, regardless of its file name. Basically, I just want a simple tag to be updated to show the image. I realize this might not be possible with Jquery, so my fallback would be PHP.
I've been trying to research how to do this, but honestly do not know where to start. Any tips to get going would be greatly appreciated,
If you want to do it with JQuery, you can! You only need to add a few lines of logic to your app.
For example, when you add images to that folder, also write a text file with the name of the image just added. Then this text file is going to always have the filename of the last image uploaded. Finally, using JavaScript(with JQuery or anything else) you do one request to the text file and then you do the second request to obtain the image with that filename.
That is just a very basic example to try to share the idea of how to do it, then depending your particular case, you can add or change a lot of details to make this works for your case.
BTW, to do it with PHP, you are going to need to execute a system command, for example 'ls -ltrh' and parse the output to obtain the last filename.
You can use PHP script to get latest modified file in a specific directory.
Code can be found here: Get last modified file in a directory
You then can format that into JSON which can be passed through a jQuery AJAX call http://api.jquery.com/jQuery.ajax/
With those 2 techniques, you can manipulate the data to display the image.

File path grabber in php or Jquery

my requirement is this :
" When users uploaded one file say "sample.tex" then i need to find the same name PDF file in that directory once he upload the "sample.tex". so file name should be "sample.pdf". we have one form that contain two input file fields.. check the image for reference.
http://img40.imageshack.us/i/proofbb.png/
once user upload the first file and click the "Show Author Email(s)" then i need to find another file "sample.pdf" in the same path and put in below file field. Is that possible in PHP or JQUERY or watever... not only PHP Even Java is also fine. Please help me to find the solution.
Regards
Dipen
You cannot do that with plain JavaScript. You can't even obtain the path information from your "first file"; all the browser will tell you is the plain file name (that is, the file name without any path information). You also cannot force a "file" input field to be set to a value.
You might be able to do this by creating a signed Java applet, but that's a whole different enchilada and you'd pretty much have to make the whole form be a Java thing.
(There's nothing you can do from PHP, as all the server will get is the plain filename and no path information at all.)
Let the user do it. Use uploadify with multiple simultaneous uploads enabled. So simple.

Image management using MySQL and image directory

A friend of mine told me that saving images in the database is not much of a good idea. Instead save it to the directory and then save it's name in the database and when I want to display the images in the browser I'm just going to use the name in the database to find the picture. Can anyone please guide me on how to do this starting from scratch?
Any help would be much appreciated.
By the way I am using php and MySQL.
Do two things:
accept more answers, here's how: https://meta.stackexchange.com/questions/5234/how-does-accepting-an-answer-work
read this tutorial: http://articles.sitepoint.com/article/php-gallery-system-minutes
What is it exactly that you don't know how to do? Your question seems to contain its own answer:
set up a directory for images, accessible to your web server
copy some image files in there
go to phpmyadmin and create a table with a filename field, for example of type varchar 100
store the image filenames in the table
write a php script that fetches image names and displays the HTML to load the images

Upload & Link an Image with php

I know this should be really simple, but im having trouble getting this to work right, basically i want to have an image upload box that uploads an image and then puts the new url into a mysql database. Anyone have any advice on how to do this, as i may be having developer block but im over complicating it in my head :P Thanks
Uploading files using php.
Assuming some kind of LAMP server, the uploaded files will be placed in a temporary directory. You will have to move them from there to their final destination and I usually give the moved files a new file name to avoid any security problems. Of course the original file-name is available so you can keep it as well, either as a file-name or as an entry in a database.
What are you precisely having problems with?

PHP / SQL picture upload to a database

I need a php code and sql code that will let someone upload an image to a database. The only thing I can find is very glictchy and not accepted by some browsers. Any ideas?
NEVER store images in the database. NEVER EVER EVER EVER. There are tons of other questions posted here about it that you may want to ready up on.
Always store directly on filesystem, and store the image URL of the file in the database.
If I understood correctly, you want to upload image files (or any files) via browser to the server and save them in the database. If that is the case, read this:
http://www.php-mysql-tutorial.com/wikis/mysql-tutorials/uploading-files-to-mysql-database.aspx
There are likely lots of available tutorials online to show you how to do this (you might take a look at this one: http://www.codewalkers.com/c/a/Database-Articles/Storing-Images-in-Database/).
I think that this is not the most efficient way to handle images, however. You might consider writing them to a folder and simply keep the name of the file and its location in the database. This stackoverflow question might help: How to store file name in database, with other info while uploading image to server using PHP?

Categories